<!DOCTYPE HTML>
<html lang="zh-CN">


<head><meta name="generator" content="Hexo 3.9.0">
    <meta charset="utf-8">
    <meta name="keywords" content="暑假LeetCode刷题集合（下）, 被动学习">
    <meta name="baidu-site-verification" content="fmlEuI34ir">
    <meta name="google-site-verification" content="yCy2azpds5XSuGZvis6OuA-XIGF5GuGpYRAaGfD6o48">
    <meta name="360-site-verification" content="b7c11a830ef90fd1464ad6206bb7b6e7">
    <meta name="description" content="【Day31】461. 汉明距离461. 汉明距离两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目。
给出两个整数 x 和 y，计算它们之间的汉明距离。
注意：

0 ≤ x, y &amp;lt; 231.

示例:
输入: x">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>暑假LeetCode刷题集合（下） | Shawlon`s Blog</title>
    <link rel="icon" type="image/jpeg" href="https://cdn.jsdelivr.net/gh/MUYIio/CDN@1.2/Images/avatars/favicon.jpg">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">
    <style type="text/css">
        
    </style>

    <script src="/libs/jquery/jquery-2.2.0.min.js"></script>
    <script src="https://sdk.jinrishici.com/v2/browser/jinrishici.js" charset="utf-8"></script>

    <script>
    var _hmt = _hmt || [];
    (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?4d1d73af45a62734730491a6b6c41da4";
    var s = document.getElementsByTagName("script")[0]; 
    s.parentNode.insertBefore(hm, s);
    })();
   </script>


    <script>(function (i, s, o, g, r, a, m) {
        i['DaoVoiceObject'] = r;
        i[r] = i[r] ||
          function () {
            (i[r].q = i[r].q || []).push(arguments);
          };
        i[r].l = 1 * new Date();
        a = s.createElement(o);
        m = s.getElementsByTagName(o)[0];
        a.async = 1;
        a.src = g;
        a.charset = 'utf-8';
        m.parentNode.insertBefore(a, m);
      })(window, document, 'script', ('https:' === document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/0fcc9bf7.js", 'daovoice');
      daovoice('init', {
        app_id: "0fcc9bf7",
      });
      daovoice('update');
    </script>
  
  


    
        <script>
            (function(){
                var bp = document.createElement('script');
                var curProtocol = window.location.protocol.split(':')[0];
                if (curProtocol === 'https') {
                    bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
                }
                else {
                    bp.src = 'http://push.zhanzhang.baidu.com/push.js';
                }
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(bp, s);
            })();
        </script>
    

    <script>
        (function(){
        var src = "https://jspassport.ssl.qhimg.com/11.0.1.js?d182b3f28525f2db83acfaaf6e696dba";
        document.write('<script src="' + src + '" id="sozz"><\/script>');
        })();
    </script>

    <meta name="baidu-site-verification" content="code-FwB5xSTmVO">




<style type="text/css" lang="css">
    #loading-container{
        position: fixed;
        top: 0;
        left: 0;
        min-height: 100vh;
        width: 100vw;
        z-index: 9999;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        background: #FFF;
        text-align: center;
        /* loaderҳ����ʧ���ý����ķ�ʽ*/
        -webkit-transition: opacity 1s ease;
        -moz-transition: opacity 1s ease;
        -o-transition: opacity 1s ease;
        transition: opacity 1s ease;
    }
    .loading-image{
        width: 120px;
        height: 50px;
        transform: translate(-50%);
    }

    .loading-image div:nth-child(2) {
        -webkit-animation: pacman-balls 1s linear 0s infinite;
        animation: pacman-balls 1s linear 0s infinite
    }

    .loading-image div:nth-child(3) {
        -webkit-animation: pacman-balls 1s linear .33s infinite;
        animation: pacman-balls 1s linear .33s infinite
    }

    .loading-image div:nth-child(4) {
        -webkit-animation: pacman-balls 1s linear .66s infinite;
        animation: pacman-balls 1s linear .66s infinite
    }

    .loading-image div:nth-child(5) {
        -webkit-animation: pacman-balls 1s linear .99s infinite;
        animation: pacman-balls 1s linear .99s infinite
    }

   .loading-image div:first-of-type {
        width: 0;
        height: 0;
        border: 25px solid #49b1f5;
        border-right-color: transparent;
        border-radius: 25px;
        -webkit-animation: rotate_pacman_half_up .5s 0s infinite;
        animation: rotate_pacman_half_up .5s 0s infinite;
    }
    .loading-image div:nth-child(2) {
        width: 0;
        height: 0;
        border: 25px solid #49b1f5;
        border-right-color: transparent;
        border-radius: 25px;
        -webkit-animation: rotate_pacman_half_down .5s 0s infinite;
        animation: rotate_pacman_half_down .5s 0s infinite;
        margin-top: -50px;
    }
    @-webkit-keyframes rotate_pacman_half_up {0% {transform: rotate(270deg)}50% {transform: rotate(1turn)}to {transform: rotate(270deg)}}

    @keyframes rotate_pacman_half_up {0% {transform: rotate(270deg)}50% {transform: rotate(1turn)}to {transform: rotate(270deg)}}

    @-webkit-keyframes rotate_pacman_half_down {0% {transform: rotate(90deg)}50% {transform: rotate(0deg)}to {transform: rotate(90deg)}}

    @keyframes rotate_pacman_half_down {0% {transform: rotate(90deg)}50% {transform: rotate(0deg)}to {transform: rotate(90deg)}}

    @-webkit-keyframes pacman-balls {75% {opacity: .7}to {transform: translate(-100px, -6.25px)}}

    @keyframes pacman-balls {75% {opacity: .7}to {transform: translate(-100px, -6.25px)}}


    .loading-image div:nth-child(3),
    .loading-image div:nth-child(4),
    .loading-image div:nth-child(5),
    .loading-image div:nth-child(6){
        background-color: #49b1f5;
        width: 15px;
        height: 15px;
        border-radius: 100%;
        margin: 2px;
        width: 10px;
        height: 10px;
        position: absolute;
        transform: translateY(-6.25px);
        top: 25px;
        left: 100px;
    }
    .loading-text{
        margin-bottom: 20vh;
        text-align: center;
        color: #2c3e50;
        font-size: 2rem;
        box-sizing: border-box;
        padding: 0 10px;
        text-shadow: 0 2px 10px rgba(0,0,0,0.2);
    }
    @media only screen and (max-width: 500px) {
         .loading-text{
            font-size: 1.5rem;
         }
    }
    .fadeout {
        opacity: 0;
        filter: alpha(opacity=0);
    }
    /* logo���ֶ��� */
    @-webkit-keyframes fadeInDown{0%{opacity:0;-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0)}100%{opacity:1;-webkit-transform:none;transform:none}}
    @keyframes fadeInDown{0%{opacity:0;-webkit-transform:translate3d(0,-100%,0);}}
 </style>
 <script>
(function () {
    const loaded = function(){
       setTimeout(function(){
            const loader = document.getElementById("loading-container");
            loader.className="fadeout" ;//ʹ�ý����ķ�������loading page
            // document.getElementById("body-wrap").style.display="flex";
            setTimeout(function(){
                loader.style.display="none";
            },1000); 
        },1000);//ǿ����ʾloading page 1s  
    };
    loaded();
})()
 </script><link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css">
<link rel="stylesheet" href="/css/prism-line-numbers.css" type="text/css"><style type="text/css" lang="css">
    #loading-container{
        position: fixed;
        top: 0;
        left: 0;
        min-height: 100vh;
        width: 100vw;
        z-index: 9999;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        background: #FFF;
        text-align: center;
        /* loaderҳ����ʧ���ý����ķ�ʽ*/
        -webkit-transition: opacity 1s ease;
        -moz-transition: opacity 1s ease;
        -o-transition: opacity 1s ease;
        transition: opacity 1s ease;
    }
    .loading-image{
        width: 120px;
        height: 50px;
        transform: translate(-50%);
    }

    .loading-image div:nth-child(2) {
        -webkit-animation: pacman-balls 1s linear 0s infinite;
        animation: pacman-balls 1s linear 0s infinite
    }

    .loading-image div:nth-child(3) {
        -webkit-animation: pacman-balls 1s linear .33s infinite;
        animation: pacman-balls 1s linear .33s infinite
    }

    .loading-image div:nth-child(4) {
        -webkit-animation: pacman-balls 1s linear .66s infinite;
        animation: pacman-balls 1s linear .66s infinite
    }

    .loading-image div:nth-child(5) {
        -webkit-animation: pacman-balls 1s linear .99s infinite;
        animation: pacman-balls 1s linear .99s infinite
    }

   .loading-image div:first-of-type {
        width: 0;
        height: 0;
        border: 25px solid #49b1f5;
        border-right-color: transparent;
        border-radius: 25px;
        -webkit-animation: rotate_pacman_half_up .5s 0s infinite;
        animation: rotate_pacman_half_up .5s 0s infinite;
    }
    .loading-image div:nth-child(2) {
        width: 0;
        height: 0;
        border: 25px solid #49b1f5;
        border-right-color: transparent;
        border-radius: 25px;
        -webkit-animation: rotate_pacman_half_down .5s 0s infinite;
        animation: rotate_pacman_half_down .5s 0s infinite;
        margin-top: -50px;
    }
    @-webkit-keyframes rotate_pacman_half_up {0% {transform: rotate(270deg)}50% {transform: rotate(1turn)}to {transform: rotate(270deg)}}

    @keyframes rotate_pacman_half_up {0% {transform: rotate(270deg)}50% {transform: rotate(1turn)}to {transform: rotate(270deg)}}

    @-webkit-keyframes rotate_pacman_half_down {0% {transform: rotate(90deg)}50% {transform: rotate(0deg)}to {transform: rotate(90deg)}}

    @keyframes rotate_pacman_half_down {0% {transform: rotate(90deg)}50% {transform: rotate(0deg)}to {transform: rotate(90deg)}}

    @-webkit-keyframes pacman-balls {75% {opacity: .7}to {transform: translate(-100px, -6.25px)}}

    @keyframes pacman-balls {75% {opacity: .7}to {transform: translate(-100px, -6.25px)}}


    .loading-image div:nth-child(3),
    .loading-image div:nth-child(4),
    .loading-image div:nth-child(5),
    .loading-image div:nth-child(6){
        background-color: #49b1f5;
        width: 15px;
        height: 15px;
        border-radius: 100%;
        margin: 2px;
        width: 10px;
        height: 10px;
        position: absolute;
        transform: translateY(-6.25px);
        top: 25px;
        left: 100px;
    }
    .loading-text{
        margin-bottom: 20vh;
        text-align: center;
        color: #2c3e50;
        font-size: 2rem;
        box-sizing: border-box;
        padding: 0 10px;
        text-shadow: 0 2px 10px rgba(0,0,0,0.2);
    }
    @media only screen and (max-width: 500px) {
         .loading-text{
            font-size: 1.5rem;
         }
    }
    .fadeout {
        opacity: 0;
        filter: alpha(opacity=0);
    }
    /* logo���ֶ��� */
    @-webkit-keyframes fadeInDown{0%{opacity:0;-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0)}100%{opacity:1;-webkit-transform:none;transform:none}}
    @keyframes fadeInDown{0%{opacity:0;-webkit-transform:translate3d(0,-100%,0);}}
 </style>
 <script>
(function () {
    const loaded = function(){
       setTimeout(function(){
            const loader = document.getElementById("loading-container");
            loader.className="fadeout" ;//ʹ�ý����ķ�������loading page
            // document.getElementById("body-wrap").style.display="flex";
            setTimeout(function(){
                loader.style.display="none";
            },1000); 
        },1000);//ǿ����ʾloading page 1s  
    };
    loaded();
})()
 </script></head>


 <div id="loading-container">
     <p class="loading-text"></p> 
     <div class="loading-image">
         <div></div>
         <div></div>
         <div></div>
         <div></div> 
         <div></div>
     </div>
 </div><body>

    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="https://cdn.jsdelivr.net/gh/MUYIio/CDN@1.2/Images/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">Shawlon`s Blog</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fa fa-navicon"></i></a>
<ul class="right">
    
    <li class="hide-on-med-and-down">
        <a href="/" class="waves-effect waves-light">
            
            <span>首页</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/tags" class="waves-effect waves-light">
            
            <span>标签</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/categories" class="waves-effect waves-light">
            
            <span>分类</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/archives" class="waves-effect waves-light">
            
            <span>归档</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/about" class="waves-effect waves-light">
            
            <span>关于</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/friends" class="waves-effect waves-light">
            
            <span>友情链接</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/contact" class="waves-effect waves-light">
            
            <span>留言板</span>
        </a>
    </li>
    
    <li>
        <a href="#searchModal" class="modal-trigger waves-effect waves-light">
            <i id="searchIcon" class="fa fa-search" title="搜索"></i>
        </a>
    </li>
</ul>

<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="https://cdn.jsdelivr.net/gh/MUYIio/CDN@1.2/Images/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">Shawlon`s Blog</div>
        <div class="logo-desc">
            
            C++ | LeetCode | Algorithm
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li>
            <a href="/" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-link"></i>
                
                首页
            </a>
        </li>
        
        <li>
            <a href="/tags" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-link"></i>
                
                标签
            </a>
        </li>
        
        <li>
            <a href="/categories" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-link"></i>
                
                分类
            </a>
        </li>
        
        <li>
            <a href="/archives" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-link"></i>
                
                归档
            </a>
        </li>
        
        <li>
            <a href="/about" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-link"></i>
                
                关于
            </a>
        </li>
        
        <li>
            <a href="/friends" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-link"></i>
                
                友情链接
            </a>
        </li>
        
        <li>
            <a href="/contact" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-link"></i>
                
                留言板
            </a>
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/muyiio" class="waves-effect waves-light" target="_blank">
                <i class="fa fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>

        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/muyiio" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    
<script src="/libs/cryptojs/crypto-js.min.js"></script>
<script>
    (function() {
        let pwd = '';
        if (pwd && pwd.length > 0) {
            if (pwd !== CryptoJS.SHA256(prompt('请输入访问本文章的密码')).toString(CryptoJS.enc.Hex)) {
                alert('密码错误，将返回主页！');
                location.href = '/';
            }
        }
    })();
</script>




<div class="bg-cover pd-header post-cover" style="background-image: url('https://cdn.jsdelivr.net/gh/MUYIio/CDN@1.2/Images/featureimages/34.jpg')">
    <div class="container">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <div class="description center-align post-title">
                        暑假LeetCode刷题集合（下）
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 20px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                        <a href="/tags/LeetCode/" target="_blank">
                            <span class="chip bg-color">LeetCode</span>
                        </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fa fa-bookmark fa-fw icon-category"></i>
                        
                        <a href="/categories/每日一题/" class="post-category" target="_blank">
                            每日一题
                        </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                <div class="post-date info-break-policy">
                    <i class="fa fa-calendar-minus-o fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2021-07-27
                </div>

                <div class="post-author info-break-policy">
                    <i class="fa fa-user-o fa-fw"></i>作者:&nbsp;&nbsp;
                    
                    Tyzhao
                    
                </div>

                
                
                <div class="info-break-policy">
                    <i class="fa fa-file-word-o fa-fw"></i>文章字数:&nbsp;&nbsp;
                    4.4k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="fa fa-clock-o fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    20 分
                </div>
                
                

                
                <div id="busuanzi_container_page_pv" class="info-break-policy">
                    <i class="fa fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                    <span id="busuanzi_value_page_pv"></span>
                </div>
                
            </div>
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h2 id="【Day31】461-汉明距离"><a href="#【Day31】461-汉明距离" class="headerlink" title="【Day31】461. 汉明距离"></a>【Day31】461. 汉明距离</h2><h4 id="461-汉明距离"><a href="#461-汉明距离" class="headerlink" title="461. 汉明距离"></a><a href="https://leetcode-cn.com/problems/hamming-distance/" target="_blank" rel="noopener">461. 汉明距离</a></h4><p>两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目。</p>
<p>给出两个整数 x 和 y，计算它们之间的汉明距离。</p>
<p><strong>注意：</strong></p>
<ul>
<li>0 ≤ x, y &lt; 231.</li>
</ul>
<p><strong>示例:</strong></p>
<pre><code>输入: x = 1, y = 4

输出: 2

解释:
1   (0 0 0 1)
4   (0 1 0 0)
       ↑   ↑

上面的箭头指出了对应二进制位不同的位置。</code></pre><p><strong>题解：</strong></p>
<p>可以考虑为求异或结果值当中1的个数，进一步转换为求二进制中1的个数。</p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    int lowbit(int x) {
        return x & (-x);
    }
    int hammingDistance(int x, int y) {
        int ret = x ^ y;
        int ans = 0;
        while (ret) {
            ret -= lowbit(ret);
            ans++;
        }
        return ans;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day32】477-汉明距离总和"><a href="#【Day32】477-汉明距离总和" class="headerlink" title="【Day32】477.汉明距离总和"></a>【Day32】477.汉明距离总和</h2><h4 id="477-汉明距离总和"><a href="#477-汉明距离总和" class="headerlink" title="477. 汉明距离总和"></a><a href="https://leetcode-cn.com/problems/total-hamming-distance/" target="_blank" rel="noopener">477. 汉明距离总和</a></h4><p>两个整数的 汉明距离 指的是这两个数字的二进制数对应位不同的数量。</p>
<p>计算一个数组中，任意两个数之间汉明距离的总和。</p>
<p><strong>示例:</strong></p>
<pre><code>输入: 4, 14, 2

输出: 6

解释: 在二进制表示中，4表示为0100，14表示为1110，2表示为0010。（这样表示是为了体现后四位之间关系）
所以答案为：
HammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6.</code></pre><p><strong>注意:</strong></p>
<ul>
<li>数组中元素的范围为从 0到 10^9。</li>
<li>数组的长度不超过 10^4。</li>
</ul>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    int totalHammingDistance(vector<int>& nums) {
        int ans = 0;
        for (int i = 0; i < 31; i++) {
            int cnt[]  = {0, 0};
            for (auto& num : nums) {
                cnt[num & 1]++;
                num >>= 1;
            }
            ans += cnt[0] * cnt[1];
        }
        return ans;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day33】1074-元素和为目标值的子矩阵数量"><a href="#【Day33】1074-元素和为目标值的子矩阵数量" class="headerlink" title="【Day33】1074.元素和为目标值的子矩阵数量"></a>【Day33】1074.元素和为目标值的子矩阵数量</h2><h4 id="1074-元素和为目标值的子矩阵数量"><a href="#1074-元素和为目标值的子矩阵数量" class="headerlink" title="1074. 元素和为目标值的子矩阵数量"></a><a href="https://leetcode-cn.com/problems/number-of-submatrices-that-sum-to-target/" target="_blank" rel="noopener">1074. 元素和为目标值的子矩阵数量</a></h4><p>给出矩阵 matrix 和目标值 target，返回元素总和等于目标值的非空子矩阵的数量。</p>
<p>子矩阵 x1, y1, x2, y2 是满足 x1 &lt;= x &lt;= x2 且 y1 &lt;= y &lt;= y2 的所有单元 matrix[x][y] 的集合。</p>
<p>如果 (x1, y1, x2, y2) 和 (x1’, y1’, x2’, y2’) 两个子矩阵中部分坐标不同（如：x1 != x1’），那么这两个子矩阵也不同。</p>
<p><strong>示例 1：</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/09/02/mate1.jpg" alt></p>
<pre><code>输入：matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0
输出：4
解释：四个只含 0 的 1x1 子矩阵。</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：matrix = [[1,-1],[-1,1]], target = 0
输出：5
解释：两个 1x2 子矩阵，加上两个 2x1 子矩阵，再加上一个 2x2 子矩阵。</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：matrix = [[904]], target = 0
输出：0</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= matrix.length &lt;= 100</li>
<li>1 &lt;= matrix[0].length &lt;= 100</li>
<li>-1000 &lt;= matrix[i] &lt;= 1000</li>
<li>-10^8 &lt;= target &lt;= 10^8</li>
</ul>
<p><strong>题解：</strong></p>
<p>二维前缀和的题目，使用哈希表来优化</p>
<pre class="line-numbers language-c++"><code class="language-c++">#define HT_LENGTH 256

struct HashTable {
    int keys[HT_LENGTH];
    int vals[HT_LENGTH];

    HashTable() {
        this->clear();
    }

    void clear() {
        keys[0] = 0; vals[0] = 1;
        for (int i = 1;i < HT_LENGTH;i++) keys[i] = -1;
    }

    bool find(int key, int& ret) {
        uint32_t ikey = (uint32_t)key % HT_LENGTH;
        for (int i = 0;i < HT_LENGTH;i++) {
            if (keys[ikey] == -1) return false;
            if (keys[ikey] == key) {
                ret = vals[ikey];
                return true;
            }
            ikey ++;
            ikey = ikey == HT_LENGTH ? 0 : ikey;
        }
        return false;
    }

    void inc(int key) {
        uint32_t ikey = (uint32_t)key % HT_LENGTH;
        for (int i = 0;i < HT_LENGTH;i++) {
            if (keys[ikey] == -1) {
                keys[ikey] = key;
                vals[ikey] = 1;
                return;
            }
            if (keys[ikey] == key) {
                vals[ikey]++;
                return;
            }
            ikey ++;
            ikey = ikey == HT_LENGTH ? 0 : ikey;
        }
    }
};

class Solution {
private:
    HashTable ht;
public:
    int numSubmatrixSumTarget(vector<vector<int>>& matrix, int target) {
        int rprefix[100][101];
        int m = matrix.size(), n = matrix[0].size();
        int ret = 0;
        for (int i = 0;i < m;i++) {
            rprefix[i][0] = 0;
            for (int j = 1;j <= n;j ++) {
                rprefix[i][j] = rprefix[i][j - 1] + matrix[i][j - 1];
            }
        }

        for (int i = 1;i <= n;i++) {
            for (int j = i;j <= n;j++) {
                ht.clear();
                int cprefix = 0, val;
                for (int row = 0;row < m;row++) {
                    cprefix += rprefix[row][j] - rprefix[row][i - 1];
                    if (ht.find(cprefix - target, val)) ret += val;
                    ht.inc(cprefix);
                }
            }
        }
        return ret;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day34】231-2-的幂"><a href="#【Day34】231-2-的幂" class="headerlink" title="【Day34】231. 2 的幂"></a>【Day34】231. 2 的幂</h2><h4 id="231-2-的幂"><a href="#231-2-的幂" class="headerlink" title="231. 2 的幂"></a><a href="https://leetcode-cn.com/problems/power-of-two/" target="_blank" rel="noopener">231. 2 的幂</a></h4><p>给你一个整数 n，请你判断该整数是否是 2 的幂次方。如果是，返回 true ；否则，返回 false 。</p>
<p>如果存在一个整数 x 使得 n == 2x ，则认为 n 是 2 的幂次方。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：n = 1
输出：true
解释：20 = 1</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：n = 16
输出：true
解释：24 = 16</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：n = 3
输出：false</code></pre><p><strong>示例 4：</strong></p>
<pre><code>输入：n = 4
输出：true</code></pre><p><strong>示例 5：</strong></p>
<pre><code>输入：n = 5
输出：false</code></pre><p><strong>提示：</strong></p>
<ul>
<li>-231 &lt;= n &lt;= 231 - 1</li>
</ul>
<p><strong>题解：</strong></p>
<p><strong>位运算</strong></p>
<p>若 n = 2^x 且 x为自然数（即 n 为 2 的幂），则一定满足以下条件：</p>
<p>首先，恒有 n &amp; (n - 1) == 0，因为：</p>
<ul>
<li>n 二进制最高位为 11，其余所有位为 00；</li>
<li>n−1 二进制最高位为 00，其余所有位为 11；</li>
</ul>
<p>其次，我们只需要限定n &gt; 0 即可。</p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    bool isPowerOfTwo(int n) {
         return n > 0 && (n & (n - 1)) == 0;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day35】342-4的幂"><a href="#【Day35】342-4的幂" class="headerlink" title="【Day35】342. 4的幂"></a>【Day35】342. 4的幂</h2><h4 id="342-4的幂"><a href="#342-4的幂" class="headerlink" title="342. 4的幂"></a><a href="https://leetcode-cn.com/problems/power-of-four/" target="_blank" rel="noopener">342. 4的幂</a></h4><p>给定一个整数，写一个函数来判断它是否是 4 的幂次方。如果是，返回 true ；否则，返回 false 。</p>
<p>整数 n 是 4 的幂次方需满足：存在整数 x 使得 n == 4x</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：n = 16
输出：true</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：n = 5
输出：false</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：n = 1
输出：true</code></pre><p><strong>提示：</strong></p>
<ul>
<li>-231 &lt;= n &lt;= 231 - 1</li>
</ul>
<p><strong>题解：</strong></p>
<p>一个数是<code>2</code>的幂，那么二进制从右边数奇数位是<code>1</code>的一定是<code>4</code>的幂。判断是<code>2</code>的幂，我们只需要判断二进制中<code>1</code>的个数，用昨天的解即可。</p>
<pre><code>0x55555555的  二进制是  01010101 01010101 01010101 01010101</code></pre><pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    bool isPowerOfFour(int n) {
    return n > 0 && (n & (n - 1)) == 0 && (n & 0x55555555) == n;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day36】LeetCode-1744"><a href="#【Day36】LeetCode-1744" class="headerlink" title="【Day36】LeetCode 1744"></a>【Day36】LeetCode 1744</h2><h4 id="1744-你能在你最喜欢的那天吃到你最喜欢的糖果吗？"><a href="#1744-你能在你最喜欢的那天吃到你最喜欢的糖果吗？" class="headerlink" title="1744. 你能在你最喜欢的那天吃到你最喜欢的糖果吗？"></a><a href="https://leetcode-cn.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day/" target="_blank" rel="noopener">1744. 你能在你最喜欢的那天吃到你最喜欢的糖果吗？</a></h4><p>给你一个下标从 <strong>0</strong> 开始的正整数数组 candiesCount ，其中 candiesCount[i] 表示你拥有的第 i 类糖果的数目。同时给你一个二维数组 queries ，其中 queries[i] = [favoriteTypei, favoriteDayi, dailyCapi] 。</p>
<p>你按照如下规则进行一场游戏：</p>
<ul>
<li>你从第 0 天开始吃糖果。</li>
<li>你在吃完 <strong>所有</strong> 第 i - 1 类糖果之前，<strong>不能</strong> 吃任何一颗第 i 类糖果。</li>
<li>在吃完所有糖果之前，你必须每天 <strong>至少</strong> 吃 一颗 糖果。</li>
</ul>
<p>请你构建一个布尔型数组 answer ，满足 answer.length == queries.length 。answer[i] 为 true 的条件是：在每天吃 <strong>不超过</strong> dailyCapi 颗糖果的前提下，你可以在第 favoriteDayi 天吃到第 favoriteTypei 类糖果；否则 answer[i] 为 false 。注意，只要满足上面 3 条规则中的第二条规则，你就可以在同一天吃不同类型的糖果。</p>
<p>请你返回得到的数组 answer 。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：candiesCount = [7,4,5,3,8], queries = [[0,2,2],[4,2,4],[2,13,1000000000]]
输出：[true,false,true]
提示：
1- 在第 0 天吃 2 颗糖果(类型 0），第 1 天吃 2 颗糖果（类型 0），第 2 天你可以吃到类型 0 的糖果。
2- 每天你最多吃 4 颗糖果。即使第 0 天吃 4 颗糖果（类型 0），第 1 天吃 4 颗糖果（类型 0 和类型 1），你也没办法在第 2 天吃到类型 4 的糖果。换言之，你没法在每天吃 4 颗糖果的限制下在第 2 天吃到第 4 类糖果。
3- 如果你每天吃 1 颗糖果，你可以在第 13 天吃到类型 2 的糖果。</code></pre><p><strong>示例 2：</strong></p>
<pre class="line-numbers language-text"><code class="language-text">输入：candiesCount = [5,2,6,4,1], queries = [[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]
输出：[false,true,true,false,false]<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= candiesCount.length &lt;= 105</li>
<li>1 &lt;= candiesCount[i] &lt;= 105</li>
<li>1 &lt;= queries.length &lt;= 105</li>
<li>queries[i].length == 3</li>
<li>0 &lt;= favoriteTypei &lt; candiesCount.length</li>
<li>0 &lt;= favoriteDayi &lt;= 109</li>
<li>1 &lt;= dailyCapi &lt;= 109</li>
</ul>
<p><strong>题解：</strong></p>
<p>使用前缀和解题：</p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    vector<long long> sum;
    bool check(vector<int>& candiesCount, vector<int>& q) {
        int favoriteType = q[0], favoriteDay = q[1], dailyCap = q[2];
        // 第favoriteType类型的前缀和
        int l = sum[favoriteType + 1];
        // 每天吃一颗糖 
        if (favoriteDay + 1 > sum[favoriteType + 1]) return false;
        // 吃最多糖
        if (sum[favoriteType] >= 1ll*(favoriteDay + 1) * dailyCap) return false;
        return true;
    }
    vector<bool> canEat(vector<int>& candiesCount, vector<vector<int>>& queries) {
        int n = candiesCount.size();
        sum = vector<long long>(n + 1, 0);
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i - 1] + candiesCount[i - 1];
        }

        vector<bool> ans;
        for (auto q : queries)
            ans.push_back(check(candiesCount, q));
        return ans;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day37】523-连续的子数组和"><a href="#【Day37】523-连续的子数组和" class="headerlink" title="【Day37】523.连续的子数组和"></a>【Day37】523.连续的子数组和</h2><h4 id="523-连续的子数组和"><a href="#523-连续的子数组和" class="headerlink" title="523. 连续的子数组和"></a><a href="https://leetcode-cn.com/problems/continuous-subarray-sum/" target="_blank" rel="noopener">523. 连续的子数组和</a></h4><p>给你一个整数数组 nums 和一个整数 k ，编写一个函数来判断该数组是否含有同时满足下述条件的连续子数组：</p>
<ul>
<li>子数组大小 <strong>至少为 2</strong> ，且</li>
<li>子数组元素总和为 k 的倍数。</li>
</ul>
<p>如果存在，返回 true ；否则，返回 false 。</p>
<p>如果存在一个整数 n ，令整数 x 符合 x = n * k ，则称 x 是 k 的一个倍数。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：nums = [23,2,4,6,7], k = 6
输出：true
解释：[2,4] 是一个大小为 2 的子数组，并且和为 6 。</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：nums = [23,2,6,4,7], k = 6
输出：true
解释：[23, 2, 6, 4, 7] 是大小为 5 的子数组，并且和为 42 。 
42 是 6 的倍数，因为 42 = 7 * 6 且 7 是一个整数。</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：nums = [23,2,6,4,7], k = 13
输出：false</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= nums.length &lt;= 105</li>
<li>0 &lt;= nums[i] &lt;= 109</li>
<li>0 &lt;= sum(nums[i]) &lt;= 231 - 1</li>
<li>1 &lt;= k &lt;= 231 - 1</li>
</ul>
<p><strong>题解：</strong></p>
<p>经典的前缀和</p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    bool checkSubarraySum(vector<int>& nums, int k) {
        int sum = 0;
        unordered_set<int> st;
        for(int i = 0; i < nums.size(); i++) {
            sum += nums[i];
            if(st.count(sum % k)) return true;
            st.insert((sum - nums[i]) % k); 
        }
        return false;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day38】525-连续数组"><a href="#【Day38】525-连续数组" class="headerlink" title="【Day38】525.连续数组"></a>【Day38】525.连续数组</h2><h4 id="525-连续数组"><a href="#525-连续数组" class="headerlink" title="525. 连续数组"></a><a href="https://leetcode-cn.com/problems/contiguous-array/" target="_blank" rel="noopener">525. 连续数组</a></h4><p>给定一个二进制数组 nums , 找到含有相同数量的 0 和 1 的最长连续子数组，并返回该子数组的长度。</p>
<p><strong>示例 1:</strong></p>
<pre><code>输入: nums = [0,1]
输出: 2
说明: [0, 1] 是具有相同数量0和1的最长连续子数组。</code></pre><p><strong>示例 2:</strong></p>
<pre><code>输入: nums = [0,1,0]
输出: 2
说明: [0, 1] (或 [1, 0]) 是具有相同数量0和1的最长连续子数组。</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= nums.length &lt;= 105</li>
<li>nums[i] 不是 0 就是 1</li>
</ul>
<p><strong>题解：</strong></p>
<p>前缀和＋哈希</p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    int findMaxLength(vector<int>& nums) {
        for (auto& num : nums) {
            num = num == 0 ? -1 : num;
        }
        map<int, int> m;
        int sum = 0, ans = 0;
        for (int i = 0; i < nums.size(); i++) {
            sum += nums[i];
            if (sum == 0) {
                ans = i + 1;
            }
            if (m.count(sum)) {
                ans = max(i - m[sum], ans);
            } else {
                m[sum] = i;
            }
        }
        return ans;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day39】160-相交链表"><a href="#【Day39】160-相交链表" class="headerlink" title="【Day39】160.相交链表"></a>【Day39】160.相交链表</h2><h4 id="160-相交链表"><a href="#160-相交链表" class="headerlink" title="160. 相交链表"></a><a href="https://leetcode-cn.com/problems/intersection-of-two-linked-lists/" target="_blank" rel="noopener">160. 相交链表</a></h4><p>给你两个单链表的头节点 headA 和 headB ，请你找出并返回两个单链表相交的起始节点。如果两个链表没有交点，返回 null 。</p>
<p>图示两个链表在节点 c1 开始相交：</p>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/14/160_statement.png" alt></p>
<p>题目数据 <strong>保证</strong> 整个链式结构中不存在环。</p>
<p><strong>注意</strong>：函数返回结果后，链表必须 保持其<strong>原始结构</strong> 。</p>
<p><strong>示例 1：</strong></p>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/14/160_example_1.png" alt></p>
<pre><code>输入：intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3
输出：Intersected at &#39;8&#39;
解释：相交节点的值为 8 （注意，如果两个链表相交则不能为 0）。
从各自的表头开始算起，链表 A 为 [4,1,8,4,5]，链表 B 为 [5,0,1,8,4,5]。
在 A 中，相交节点前有 2 个节点；在 B 中，相交节点前有 3 个节点。</code></pre><p><strong>示例 2：</strong></p>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/14/160_example_2.png" alt></p>
<pre><code>输入：intersectVal = 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1
输出：Intersected at &#39;2&#39;
解释：相交节点的值为 2 （注意，如果两个链表相交则不能为 0）。
从各自的表头开始算起，链表 A 为 [0,9,1,2,4]，链表 B 为 [3,2,4]。
在 A 中，相交节点前有 3 个节点；在 B 中，相交节点前有 1 个节点。</code></pre><p><strong>示例 3：</strong></p>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/14/160_example_3.png" alt></p>
<pre><code>输入：intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2
输出：null
解释：从各自的表头开始算起，链表 A 为 [2,6,4]，链表 B 为 [1,5]。
由于这两个链表不相交，所以 intersectVal 必须为 0，而 skipA 和 skipB 可以是任意值。
这两个链表不相交，因此返回 null 。</code></pre><p><strong>提示：</strong></p>
<ul>
<li>listA 中节点数目为 m</li>
<li>listB 中节点数目为 n</li>
<li>0 &lt;= m, n &lt;= 3 * 104</li>
<li>1 &lt;= Node.val &lt;= 105</li>
<li>0 &lt;= skipA &lt;= m</li>
<li>0 &lt;= skipB &lt;= n</li>
<li>如果 listA 和 listB 没有交点，intersectVal 为 0</li>
<li>如果 listA 和 listB 有交点，intersectVal == listA[skipA + 1] == listB[skipB + 1]</li>
</ul>
<p><strong>进阶：</strong>你能否设计一个时间复杂度 <code>O(n)</code> 、仅用 <code>O(1)</code> 内存的解决方案？</p>
<p><strong>题解：</strong></p>
<p>pA走过的路径为A链+B链</p>
<p>pB走过的路径为B链+A链</p>
<p>pA和pB走过的长度都相同，都是A链和B链的长度之和，相当于将两条链从尾端对齐，如果相交，则会提前在相交点相遇，如果没有相交点，则会在最后相遇。</p>
<pre><code>pA:1-&gt;2-&gt;3-&gt;4-&gt;5-&gt;6-&gt;null-&gt;9-&gt;5-&gt;6-&gt;null
pB:9-&gt;5-&gt;6-&gt;null-&gt;1-&gt;2-&gt;3-&gt;4-&gt;5-&gt;6-&gt;null</code></pre><pre class="line-numbers language-c++"><code class="language-c++">/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
        ListNode *p = headA, *q = headB;
        while (p != q) {
            p = p ? p->next : headB;
            q = q ? q->next : headA;
        }
        return p;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day40】203-移除链表元素"><a href="#【Day40】203-移除链表元素" class="headerlink" title="【Day40】203.移除链表元素"></a>【Day40】203.移除链表元素</h2><h4 id="203-移除链表元素"><a href="#203-移除链表元素" class="headerlink" title="203. 移除链表元素"></a><a href="https://leetcode-cn.com/problems/remove-linked-list-elements/" target="_blank" rel="noopener">203. 移除链表元素</a></h4><p>给你一个链表的头节点 head 和一个整数 val ，请你删除链表中所有满足 Node.val == val 的节点，并返回 新的头节点 。</p>
<p><strong>示例 1：</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/03/06/removelinked-list.jpg" alt></p>
<pre><code>输入：head = [1,2,6,3,4,5,6], val = 6
输出：[1,2,3,4,5]</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：head = [], val = 1
输出：[]</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：head = [7,7,7,7], val = 7
输出：[]</code></pre><p><strong>提示：</strong></p>
<ul>
<li>列表中的节点在范围 [0, 104] 内</li>
<li>1 &lt;= Node.val &lt;= 50</li>
<li>0 &lt;= k &lt;= 50</li>
</ul>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode *removeElements(ListNode *head, int val)
    {
        if (!head)
            return head;
        head->next = removeElements(head->next, val);
        return head->val == val ? head->next : head;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day41】474-一和零"><a href="#【Day41】474-一和零" class="headerlink" title="【Day41】474.一和零"></a>【Day41】474.一和零</h2><h4 id="474-一和零"><a href="#474-一和零" class="headerlink" title="474. 一和零"></a><a href="https://leetcode-cn.com/problems/ones-and-zeroes/" target="_blank" rel="noopener">474. 一和零</a></h4><p>给你一个二进制字符串数组 strs 和两个整数 m 和 n 。</p>
<p>请你找出并返回 strs 的最大子集的大小，该子集中 <strong>最多</strong> 有 m 个 0 和 n 个 1 。</p>
<p>如果 x 的所有元素也是 y 的元素，集合 x 是集合 y 的 <strong>子集</strong> 。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：strs = [&quot;10&quot;, &quot;0001&quot;, &quot;111001&quot;, &quot;1&quot;, &quot;0&quot;], m = 5, n = 3
输出：4
解释：最多有 5 个 0 和 3 个 1 的最大子集是 {&quot;10&quot;,&quot;0001&quot;,&quot;1&quot;,&quot;0&quot;} ，因此答案是 4 。
其他满足题意但较小的子集包括 {&quot;0001&quot;,&quot;1&quot;} 和 {&quot;10&quot;,&quot;1&quot;,&quot;0&quot;} 。{&quot;111001&quot;} 不满足题意，因为它含 4 个 1 ，大于 n 的值 3 。</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：strs = [&quot;10&quot;, &quot;0&quot;, &quot;1&quot;], m = 1, n = 1
输出：2
解释：最大的子集是 {&quot;0&quot;, &quot;1&quot;} ，所以答案是 2 。</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= strs.length &lt;= 600</li>
<li>1 &lt;= strs[i].length &lt;= 100</li>
<li>strs[i] 仅由 ‘0’ 和 ‘1’ 组成</li>
<li>1 &lt;= m, n &lt;= 100</li>
</ul>
<p><strong>题解：</strong></p>
<p>动态规划</p>
<pre class="line-numbers language-c++"><code class="language-c++">const int N = 101;
class Solution {
public:
    int dp[N][N];

    int findMaxForm(vector<string>& strs, int m, int n)
    {
        for (auto &str:strs)
        {
            int one = 0, zero = 0;
            for (auto &c:str)
            {
                if(c=='1')
                    ++one;
                else
                    ++zero;
            }
            // zero = str.size() - one;
            for (int j=m; j>=zero; --j)
            {
                for (int k=n; k>=one; --k)
                {
                    dp[j][k] = max(dp[j][k], dp[j-zero][k-one] + 1);
                }
            }
        }
        return dp[m][n];
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day42】494-目标和"><a href="#【Day42】494-目标和" class="headerlink" title="【Day42】494. 目标和"></a>【Day42】494. 目标和</h2><h4 id="494-目标和"><a href="#494-目标和" class="headerlink" title="494. 目标和"></a><a href="https://leetcode-cn.com/problems/target-sum/" target="_blank" rel="noopener">494. 目标和</a></h4><p>给你一个整数数组 nums 和一个整数 target 。</p>
<p>向数组中的每个整数前添加 ‘+’ 或 ‘-‘ ，然后串联起所有整数，可以构造一个 <strong>表达式</strong> ：</p>
<blockquote>
<p>例如，nums = [2, 1] ，可以在 2 之前添加 ‘+’ ，在 1 之前添加 ‘-‘ ，然后串联起来得到表达式 “+2-1” 。</p>
</blockquote>
<p>返回可以通过上述方法构造的、运算结果等于 target 的不同 <strong>表达式</strong> 的数目。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：nums = [1,1,1,1,1], target = 3
输出：5
解释：一共有 5 种方法让最终目标和为 3 。
-1 + 1 + 1 + 1 + 1 = 3
+1 - 1 + 1 + 1 + 1 = 3
+1 + 1 - 1 + 1 + 1 = 3
+1 + 1 + 1 - 1 + 1 = 3
+1 + 1 + 1 + 1 - 1 = 3</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：nums = [1], target = 1
输出：1</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= nums.length &lt;= 20</li>
<li>0 &lt;= nums[i] &lt;= 1000</li>
<li>0 &lt;= sum(nums[i]) &lt;= 1000</li>
<li>-1000 &lt;= target &lt;= 100</li>
</ul>
<p><strong>题解：</strong></p>
<p>还是动态规划</p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
    int n;
    int ans = 0;
    int t;
public:
    int findTargetSumWays(vector<int>& nums, int target) {
        n = nums.size();
        t = target;
        dfs(0,nums,  0);
        return ans;
    }
    void dfs(int u, vector <int> & nums, int s){
        if(u == n){
            if(s == t) ++ans;
            return;
        }
        dfs(u + 1, nums, s + nums[u]);
        dfs(u + 1, nums, s - nums[u]);
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day43】1049-最后一块石头的重量-II"><a href="#【Day43】1049-最后一块石头的重量-II" class="headerlink" title="【Day43】1049. 最后一块石头的重量 II"></a>【Day43】1049. 最后一块石头的重量 II</h2><h4 id="1049-最后一块石头的重量-II"><a href="#1049-最后一块石头的重量-II" class="headerlink" title="1049. 最后一块石头的重量 II"></a><a href="https://leetcode-cn.com/problems/last-stone-weight-ii/" target="_blank" rel="noopener">1049. 最后一块石头的重量 II</a></h4><p>有一堆石头，用整数数组 stones 表示。其中 stones[i] 表示第 i 块石头的重量。</p>
<p>每一回合，从中选出<strong>任意两块石头</strong>，然后将它们一起粉碎。假设石头的重量分别为 x 和 y，且 x &lt;= y。那么粉碎的可能结果如下：</p>
<ul>
<li>如果 x == y，那么两块石头都会被完全粉碎；</li>
<li>如果 x != y，那么重量为 x 的石头将会完全粉碎，而重量为 y 的石头新重量为 y-x。</li>
</ul>
<p>最后，<strong>最多只会剩下一块 石头</strong>。返回此石头 <strong>最小的可能重量</strong> 。如果没有石头剩下，就返回 0。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：stones = [2,7,4,1,8,1]
输出：1
解释：
组合 2 和 4，得到 2，所以数组转化为 [2,7,1,8,1]，
组合 7 和 8，得到 1，所以数组转化为 [2,1,1,1]，
组合 2 和 1，得到 1，所以数组转化为 [1,1,1]，
组合 1 和 1，得到 0，所以数组转化为 [1]，这就是最优值。</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：stones = [31,26,33,21,40]
输出：5</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：stones = [1,2]
输出：1</code></pre><p><strong>提示：</strong></p>
<ul>
<li><p>1 &lt;= stones.length &lt;= 30</p>
</li>
<li><p>1 &lt;= stones[i] &lt;= 100</p>
<p><strong>题解：</strong></p>
</li>
</ul>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    int lastStoneWeightII(vector<int>& stones) {
        auto sum = accumulate(stones.begin(), stones.end(), 0);
        vector<int> dp(sum / 2 + 1);
        for (const auto& stone : stones) {
            for (auto j = sum / 2; j >= stone; j--) {
                dp[j] = max(dp[j], dp[j - stone] + stone);
            }
        }
        return sum - dp[sum / 2] * 2;
    }
};
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day44】879-盈利计划"><a href="#【Day44】879-盈利计划" class="headerlink" title="【Day44】879. 盈利计划"></a>【Day44】879. 盈利计划</h2><h4 id="879-盈利计划"><a href="#879-盈利计划" class="headerlink" title="879. 盈利计划"></a><a href="https://leetcode-cn.com/problems/profitable-schemes/" target="_blank" rel="noopener">879. 盈利计划</a></h4><p>集团里有 n 名员工，他们可以完成各种各样的工作创造利润。</p>
<p>第 i 种工作会产生 profit[i] 的利润，它要求 group[i] 名成员共同参与。如果成员参与了其中一项工作，就不能参与另一项工作。</p>
<p>工作的任何至少产生 minProfit 利润的子集称为 <strong>盈利计划</strong> 。并且工作的成员总数最多为 n 。</p>
<p>有多少种计划可以选择？因为答案很大，所以 <strong>返回结果模</strong> 10^9 + 7 的<strong>值</strong>。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：n = 5, minProfit = 3, group = [2,2], profit = [2,3]
输出：2
解释：至少产生 3 的利润，该集团可以完成工作 0 和工作 1 ，或仅完成工作 1 。
总的来说，有两种计划。</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：n = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8]
输出：7
解释：至少产生 5 的利润，只要完成其中一种工作就行，所以该集团可以完成任何工作。
有 7 种可能的计划：(0)，(1)，(2)，(0,1)，(0,2)，(1,2)，以及 (0,1,2) 。</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= n &lt;= 100</li>
<li>0 &lt;= minProfit &lt;= 100</li>
<li>1 &lt;= group.length &lt;= 100</li>
<li>1 &lt;= group[i] &lt;= 100</li>
<li>profit.length == group.length</li>
<li>0 &lt;= profit[i] &lt;= 100</li>
</ul>
<p><strong>题解：</strong></p>
<p>这题不会，贴一个题解吧</p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    int profitableSchemes(int n, int minProfit, vector<int>& group, vector<int>& profit) {
        int mod = 1e9 + 7;
        int size = group.size();
        int dp[n + 1][minProfit + 1];
        memset(dp, 0, sizeof(dp));
        for (int i = 0; i <= n; ++i) {
            dp[i][0] = 1;
        }

        for (int i = 1; i <= size; ++i) {
            int cur_group = group[i - 1], cur_profit = profit[i - 1];
            for (int j = n; j >= cur_group; --j) {
                for (int k = minProfit; k >= 0; --k) {
                    dp[j][k] += dp[j - cur_group][max(k - cur_profit, 0)];
                    dp[j][k] %= mod;
                }
            }
        }
        return dp[n][minProfit];
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day45】518-零钱兑换-II"><a href="#【Day45】518-零钱兑换-II" class="headerlink" title="【Day45】518. 零钱兑换 II"></a>【Day45】518. 零钱兑换 II</h2><h4 id="518-零钱兑换-II"><a href="#518-零钱兑换-II" class="headerlink" title="518. 零钱兑换 II"></a><a href="https://leetcode-cn.com/problems/coin-change-2/" target="_blank" rel="noopener">518. 零钱兑换 II</a></h4><p>给定不同面额的硬币和一个总金额。写出函数来计算可以凑成总金额的硬币组合数。假设每一种面额的硬币有无限个。 </p>
<p><strong>示例 1:</strong></p>
<pre><code>输入: amount = 5, coins = [1, 2, 5]
输出: 4
解释: 有四种方式可以凑成总金额:
5=5
5=2+2+1
5=2+1+1+1
5=1+1+1+1+1</code></pre><p><strong>示例 2:</strong></p>
<pre><code>输入: amount = 3, coins = [2]
输出: 0
解释: 只用面额2的硬币不能凑成总金额3。</code></pre><p><strong>示例 3:</strong></p>
<pre><code>输入: amount = 10, coins = [10] 
输出: 1</code></pre><p><strong>注意:</strong></p>
<ul>
<li>0 &lt;= amount (总金额) &lt;= 5000</li>
<li>1 &lt;= coin (硬币面额) &lt;= 5000</li>
<li>硬币种类不超过 500 种</li>
<li>结果符合 32 位符号整数</li>
</ul>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    int change(int amount, vector<int>& coins) {
        int n = coins.size();
        vector<int> dp(amount+1);
        dp[0] = 1;
        for(int i = 1; i<=n; i++)
        {
            int val = coins[i-1];
            for(int j = val; j <= amount;++j)
            {
                dp[j] += dp[j-val];
            }
        }
        return dp[amount];
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day46】279-完全平方数"><a href="#【Day46】279-完全平方数" class="headerlink" title="【Day46】279. 完全平方数"></a>【Day46】279. 完全平方数</h2><h4 id="279-完全平方数"><a href="#279-完全平方数" class="headerlink" title="279. 完全平方数"></a><a href="https://leetcode-cn.com/problems/perfect-squares/" target="_blank" rel="noopener">279. 完全平方数</a></h4><p>给定正整数 n，找到若干个完全平方数（比如 1, 4, 9, 16, …）使得它们的和等于 n。你需要让组成和的完全平方数的个数最少。</p>
<p>给你一个整数 n ，返回和为 n 的完全平方数的 <strong>最少数量</strong> 。</p>
<p><strong>完全平方数</strong> 是一个整数，其值等于另一个整数的平方；换句话说，其值等于一个整数自乘的积。例如，1、4、9 和 16 都是完全平方数，而 3 和 11 不是。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：n = 12
输出：3 
解释：12 = 4 + 4 + 4</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：n = 13
输出：2
解释：13 = 4 + 9</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= n &lt;= 104</li>
</ul>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">//假设最小公式值m = ƒ(n) 
//那么n的值满足下列公式 ∑(A[i] * A[i]) = n 
//令 k 为满足最小值 m 的时候，最大的平方数  。 令  d + k * k; = n ;  d >= 0; 
   // 注意：一定要是满足m最小的时候的k值,一味的取最大平方数,就是贪心算法了
//得出 f(d) + f(k*k) = f(n);
//显然 f(k*k) = 1; 则  f(d) + 1 = f(n); 因为 d = n - k*k;
//则可以推出ƒ(n - k * k) + 1 = ƒ(n) ;  且 k * k <= n;

class Solution {
public:
    int numSquares(int n) {
        if (n <= 0) return 0;
        std::vector<int> nums(n+1);
        for(int i = 1; i <= n;i++)
        {
            int min = i;
            for(int j = 1;i - j*j >= 0;j++)
            {
                int tmp = nums[i-j*j] + 1;
                min = min > tmp ?  tmp:min; 
            }
            nums[i] = min;
        }
        return nums[n];

    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day47】1449-数位成本和为目标值的最大数字"><a href="#【Day47】1449-数位成本和为目标值的最大数字" class="headerlink" title="【Day47】1449. 数位成本和为目标值的最大数字"></a>【Day47】1449. 数位成本和为目标值的最大数字</h2><h4 id="1449-数位成本和为目标值的最大数字"><a href="#1449-数位成本和为目标值的最大数字" class="headerlink" title="1449. 数位成本和为目标值的最大数字"></a><a href="https://leetcode-cn.com/problems/form-largest-integer-with-digits-that-add-up-to-target/" target="_blank" rel="noopener">1449. 数位成本和为目标值的最大数字</a></h4><p>给你一个整数数组 cost 和一个整数 target 。请你返回满足如下规则可以得到的 <strong>最大</strong> 整数：</p>
<ul>
<li>给当前结果添加一个数位（i + 1）的成本为 cost[i] （cost 数组下标从 0 开始）。</li>
<li>总成本必须恰好等于 target 。</li>
<li>添加的数位中没有数字 0 。</li>
</ul>
<p>由于答案可能会很大，请你以字符串形式返回。</p>
<p>如果按照上述要求无法得到任何整数，请你返回 “0” 。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：cost = [4,3,2,5,6,7,2,5,5], target = 9
输出：&quot;7772&quot;
解释：添加数位 &#39;7&#39; 的成本为 2 ，添加数位 &#39;2&#39; 的成本为 3 。所以 &quot;7772&quot; 的代价为 2*3+ 3*1 = 9 。 &quot;977&quot; 也是满足要求的数字，但 &quot;7772&quot; 是较大的数字。
 数字     成本
  1  -&gt;   4
  2  -&gt;   3
  3  -&gt;   2
  4  -&gt;   5
  5  -&gt;   6
  6  -&gt;   7
  7  -&gt;   2
  8  -&gt;   5
  9  -&gt;   5</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：cost = [7,6,5,5,5,6,8,7,8], target = 12
输出：&quot;85&quot;
解释：添加数位 &#39;8&#39; 的成本是 7 ，添加数位 &#39;5&#39; 的成本是 5 。&quot;85&quot; 的成本为 7 + 5 = 12 。</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：cost = [2,4,6,2,4,6,4,4,4], target = 5
输出：&quot;0&quot;
解释：总成本是 target 的条件下，无法生成任何整数。</code></pre><p><strong>示例 4：</strong></p>
<pre><code>输入：cost = [6,10,15,40,40,40,40,40,40], target = 47
输出：&quot;32211&quot;</code></pre><p><strong>提示：</strong></p>
<ul>
<li>cost.length == 9</li>
<li>1 &lt;= cost[i] &lt;= 5000</li>
<li>1 &lt;= target &lt;= 5000</li>
</ul>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    string largestNumber(vector<int>& cost, int target) {
        int len=cost.size();
        vector<string> dp(target+1,"#");
        dp[0]="";
        //因为i遍历的顺序是从小到大，就保证了整数的高位一定大于等于整数的低位，也就保证了整数最大
        for(int i=1;i<len+1;++i)
            for(int j=1;j<target+1;++j){    
                if(j>=cost[i-1]&&dp[j-cost[i-1]]!="#"){
                    dp[j]=CompareString(dp[j],to_string(i)+dp[j-cost[i-1]]);
                }
            }
        return dp[target]=="#"?"0":dp[target];
    }
private:
    string CompareString(const string& s1,const string& s2){
        int m=s1.size(),n=s2.size();
        if(m==n)return max(s1,s2);
        return m>n?s1:s2;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day48】278-第一个错误的版本"><a href="#【Day48】278-第一个错误的版本" class="headerlink" title="【Day48】278. 第一个错误的版本"></a>【Day48】278. 第一个错误的版本</h2><h4 id="278-第一个错误的版本"><a href="#278-第一个错误的版本" class="headerlink" title="278. 第一个错误的版本"></a><a href="https://leetcode-cn.com/problems/first-bad-version/" target="_blank" rel="noopener">278. 第一个错误的版本</a></h4><p>你是产品经理，目前正在带领一个团队开发新的产品。不幸的是，你的产品的最新版本没有通过质量检测。由于每个版本都是基于之前的版本开发的，所以错误的版本之后的所有版本都是错的。</p>
<p>假设你有 n 个版本 [1, 2, …, n]，你想找出导致之后所有版本出错的第一个错误的版本。</p>
<p>你可以通过调用 bool isBadVersion(version) 接口来判断版本号 version 是否在单元测试中出错。实现一个函数来查找第一个错误的版本。你应该尽量减少对调用 API 的次数。</p>
<p><strong>示例:</strong></p>
<pre><code>给定 n = 5，并且 version = 4 是第一个错误的版本。

调用 isBadVersion(3) -&gt; false
调用 isBadVersion(5) -&gt; true
调用 isBadVersion(4) -&gt; true

所以，4 是第一个错误的版本。 </code></pre><p><strong>题解：</strong></p>
<p>二分</p>
<pre class="line-numbers language-c++"><code class="language-c++">bool isBadVersion(int version);

class Solution {
public:
    int firstBadVersion(int n) {
        int lo = 1;
        int hi = n;

        while(lo < hi) {
            int mid = lo + (hi - lo) / 2;
            if (isBadVersion(mid)) {
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }
        return hi;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day49】374-猜数字大小"><a href="#【Day49】374-猜数字大小" class="headerlink" title="【Day49】374. 猜数字大小"></a>【Day49】374. 猜数字大小</h2><h4 id="374-猜数字大小"><a href="#374-猜数字大小" class="headerlink" title="374. 猜数字大小"></a><a href="https://leetcode-cn.com/problems/guess-number-higher-or-lower/" target="_blank" rel="noopener">374. 猜数字大小</a></h4><p>猜数字游戏的规则如下：</p>
<ul>
<li>每轮游戏，我都会从 1 到 n 随机选择一个数字。 请你猜选出的是哪个数字。</li>
<li>如果你猜错了，我会告诉你，你猜测的数字比我选出的数字是大了还是小了。</li>
</ul>
<p>你可以通过调用一个预先定义好的接口 int guess(int num) 来获取猜测结果，返回值一共有 3 种可能的情况（-1，1 或 0）：</p>
<ul>
<li>-1：我选出的数字比你猜的数字小 pick &lt; num</li>
<li>1：我选出的数字比你猜的数字大 pick &gt; num</li>
<li>0：我选出的数字和你猜的数字一样。恭喜！你猜对了！pick == num</li>
</ul>
<p>返回我选出的数字。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：n = 10, pick = 6
输出：6</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：n = 1, pick = 1
输出：1</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：n = 2, pick = 1
输出：1</code></pre><p><strong>示例 4：</strong></p>
<pre><code>输入：n = 2, pick = 2
输出：2</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= n &lt;= 231 - 1</li>
<li>1 &lt;= pick &lt;= n</li>
</ul>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">/** 
 * Forward declaration of guess API.
 * @param  num   your guess
 * @return          -1 if num is lower than the guess number
 *                  1 if num is higher than the guess number
 *               otherwise return 0
 * int guess(int num);
 */

class Solution {
public:
    int guessNumber(int n) {
        int l = 0;
        int r = n;
        while (l <= r)
        {
            int m = (l-r)/2 + r;
            int res = guess(m);
            if (res == 0)
            {
                return m;
            }
            else if (res < 0)
            {
                r = m-1;
            }
            else
            {
                l = m + 1;
            }
        }

        return -1;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day50】852-山脉数组的峰顶索引"><a href="#【Day50】852-山脉数组的峰顶索引" class="headerlink" title="【Day50】852. 山脉数组的峰顶索引"></a>【Day50】852. 山脉数组的峰顶索引</h2><h4 id="852-山脉数组的峰顶索引"><a href="#852-山脉数组的峰顶索引" class="headerlink" title="852. 山脉数组的峰顶索引"></a><a href="https://leetcode-cn.com/problems/peak-index-in-a-mountain-array/" target="_blank" rel="noopener">852. 山脉数组的峰顶索引</a></h4><p>符合下列属性的数组 arr 称为 <strong>山脉数组</strong> ：</p>
<ul>
<li><p>arr.length &gt;= 3</p>
</li>
<li><p>存在 i（0 &lt; i &lt; arr.length - 1）使得：</p>
<ul>
<li>arr[0] &lt; arr[1] &lt; … arr[i-1] &lt; arr[i]</li>
<li>arr[i] &gt; arr[i+1] &gt; … &gt; arr[arr.length - 1]</li>
</ul>
<p>给你由整数组成的山脉数组 arr ，返回任何满足 arr[0] &lt; arr[1] &lt; … arr[i - 1] &lt; arr[i] &gt; arr[i + 1] &gt; … &gt; arr[arr.length - 1] 的下标 i 。</p>
</li>
</ul>
<p><strong>示例 1：</strong></p>
<pre><code>输入：arr = [0,1,0]
输出：1</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：arr = [0,2,1,0]
输出：1</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：arr = [0,10,5,2]
输出：1</code></pre><p><strong>示例 4：</strong></p>
<pre><code>输入：arr = [3,4,5,1]
输出：2</code></pre><p><strong>示例 5：</strong></p>
<pre><code>输入：arr = [24,69,100,99,79,78,67,36,26,19]
输出：2</code></pre><p><strong>提示：</strong></p>
<ul>
<li>3 &lt;= arr.length &lt;= 104</li>
<li>0 &lt;= arr[i] &lt;= 106</li>
<li>题目数据保证 arr 是一个山脉数组</li>
</ul>
<p><strong>题解：</strong></p>
<p>二分法</p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    int peakIndexInMountainArray(vector<int>& arr) {
            //根据 arr[mid-1]和arr[mid]对比
        //所以搜索范围是 [1,arr.length -1]
        int left = 1;
        int right = arr.size() - 1;

        while(left < right){
            //如果check 函数调整的是left，则+1. 否则有可能陷入死循环
            int mid = left + right + 1 >> 1;
            if(arr[mid-1] < arr[mid])
            left = mid;
            else
            right = mid -1;
        }
        return right;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day51】877-石子游戏"><a href="#【Day51】877-石子游戏" class="headerlink" title="【Day51】877. 石子游戏"></a>【Day51】877. 石子游戏</h2><h4 id="877-石子游戏"><a href="#877-石子游戏" class="headerlink" title="877. 石子游戏"></a><a href="https://leetcode-cn.com/problems/stone-game/" target="_blank" rel="noopener">877. 石子游戏</a></h4><p>亚历克斯和李用几堆石子在做游戏。偶数堆石子<strong>排成一行</strong>，每堆都有正整数颗石子 piles[i] 。</p>
<p>游戏以谁手中的石子最多来决出胜负。石子的总数是奇数，所以没有平局。</p>
<p>亚历克斯和李轮流进行，亚历克斯先开始。 每回合，玩家从行的开始或结束处取走整堆石头。 这种情况一直持续到没有更多的石子堆为止，此时手中石子最多的玩家获胜。</p>
<p>假设亚历克斯和李都发挥出最佳水平，当亚历克斯赢得比赛时返回 true ，当李赢得比赛时返回 false 。</p>
<p><strong>示例：</strong></p>
<pre><code>输入：[5,3,4,5]
输出：true
解释：
亚历克斯先开始，只能拿前 5 颗或后 5 颗石子 。
假设他取了前 5 颗，这一行就变成了 [3,4,5] 。
如果李拿走前 3 颗，那么剩下的是 [4,5]，亚历克斯拿走后 5 颗赢得 10 分。
如果李拿走后 5 颗，那么剩下的是 [3,4]，亚历克斯拿走后 4 颗赢得 9 分。
这表明，取前 5 颗石子对亚历克斯来说是一个胜利的举动，所以我们返回 true 。</code></pre><p><strong>提示：</strong></p>
<ul>
<li>2 &lt;= piles.length &lt;= 500</li>
<li>piles.length 是偶数。</li>
<li>1 &lt;= piles[i] &lt;= 500</li>
<li>sum(piles) 是奇数。</li>
</ul>
<p><strong>题解：</strong></p>
<p><strong>博弈论</strong></p>
<p><a href="https://leetcode-cn.com/problems/stone-game/solution/gong-shui-san-xie-jing-dian-qu-jian-dp-j-wn31/" target="_blank" rel="noopener">三叶的题解</a></p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    bool stoneGame(vector<int>& piles) {
        return true;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day52】65-有效数字"><a href="#【Day52】65-有效数字" class="headerlink" title="【Day52】65. 有效数字"></a>【Day52】65. 有效数字</h2><p><strong>有效数字</strong>（按顺序）可以分成以下几个部分：</p>
<ol>
<li>一个 <strong>小数</strong> 或者 <strong>整数</strong></li>
<li>（可选）一个 ‘e’ 或 ‘E’ ，后面跟着一个 <strong>整数</strong></li>
</ol>
<p><strong>小数</strong>（按顺序）可以分成以下几个部分：</p>
<ol>
<li>（可选）一个符号字符（’+’ 或 ‘-‘）</li>
<li>下述格式之一：<ol>
<li>至少一位数字，后面跟着一个点 ‘.’</li>
<li>至少一位数字，后面跟着一个点 ‘.’ ，后面再跟着至少一位数字</li>
<li>一个点 ‘.’ ，后面跟着至少一位数字</li>
</ol>
</li>
</ol>
<p><strong>整数</strong>（按顺序）可以分成以下几个部分：</p>
<ul>
<li>（可选）一个符号字符（’+’ 或 ‘-‘）</li>
<li>至少一位数字</li>
</ul>
<p>部分有效数字列举如下：</p>
<ul>
<li>[“2”, “0089”, “-0.1”, “+3.14”, “4.”, “-.9”, “2e10”, “-90E3”, “3e+7”, “+6e-1”, “53.5e93”, “-123.456e789”]</li>
</ul>
<p>部分无效数字列举如下：</p>
<ul>
<li>[“abc”, “1a”, “1e”, “e3”, “99e2.5”, “–6”, “-+3”, “95a54e53”]</li>
</ul>
<p>给你一个字符串 s ，如果 s 是一个 <strong>有效数字</strong> ，请返回 true 。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：s = &quot;0&quot;
输出：true</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：s = &quot;e&quot;
输出：false</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：s = &quot;.&quot;
输出：false</code></pre><p><strong>示例 4：</strong></p>
<pre><code>输入：s = &quot;.1&quot;
输出：true</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= s.length &lt;= 20</li>
<li>s 仅含英文字母（大写和小写），数字（0-9），加号 ‘+’ ，减号 ‘-‘ ，或者点 ‘.’ 。</li>
</ul>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    bool isNumber(string s) {
        int l = 0, r = s.size() - 1;
        //去掉前后空格
        while (l <= r && s[l] == ' ') l ++ ;
        while (l <= r && s[r] == ' ') r -- ;
        if (l > r) return false;
        s = s.substr(l, r - l + 1);
        //去掉正负号
        if (s[0] == '+' || s[0] == '-') s = s.substr(1);
        //如果只有正负号，false
        if (s.empty()) return false;
        //如果只有一个点，或者.e || .E 返回false
        if (s[0] == '.' && (s.size() == 1 || s[1] == 'e' || s[1] == 'E'))
            return false;

        //记录点和e的次数
        int dot = 0, e = 0;
        for (int i = 0; i < s.size(); i ++ ) {
            if (s[i] == '.') {
                //如果出现多个点或者e ，fasle
                if (dot > 0 || e > 0) return false;
                dot ++ ;
            } else if (s[i] == 'e' || s[i] == 'E') {
                //如果e的前面没东西或者后面没东西，或者多个e ，false
                if (!i || i + 1 == s.size() || e > 0) return false;
                //如果e的后面是正负号
                if (s[i + 1] == '+' || s[i + 1] == '-') {
                    //但是后面没东西了，返回false
                    if (i + 2 == s.size()) return false;
                    i ++ ;
                }
                e ++ ;
                //不合法
            } else if (s[i] < '0' || s[i] > '9') return false;
        }
        return true;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day53】483-最小好进制"><a href="#【Day53】483-最小好进制" class="headerlink" title="【Day53】483. 最小好进制"></a>【Day53】483. 最小好进制</h2><h4 id="483-最小好进制"><a href="#483-最小好进制" class="headerlink" title="483. 最小好进制"></a><a href="https://leetcode-cn.com/problems/smallest-good-base/" target="_blank" rel="noopener">483. 最小好进制</a></h4><p>对于给定的整数 n, 如果n的k（k&gt;=2）进制数的所有数位全为1，则称 k（k&gt;=2）是 n 的一个<strong>好进制</strong>。</p>
<p>以字符串的形式给出 n, 以字符串的形式返回 n 的最小好进制。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：&quot;13&quot;
输出：&quot;3&quot;
解释：13 的 3 进制是 111。</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：&quot;4681&quot;
输出：&quot;8&quot;
解释：4681 的 8 进制是 11111。</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：&quot;1000000000000000000&quot;
输出：&quot;999999999999999999&quot;
解释：1000000000000000000 的 999999999999999999 进制是 11。</code></pre><p><strong>提示：</strong></p>
<ol>
<li>n的取值范围是 [3, 10^18]。</li>
<li>输入总是有效且没有前导 0。</li>
</ol>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    using LL = long long;
    string smallestGoodBase(string n) {
        LL x = stoll(n);
        for(int m = 2; m <= 60; m++){
            LL k = (LL)pow(x, 1. / m);
            if(k > 1){
                LL cur = 1;
                for(LL i = 1, base = 1; i <= m; i++){
                    base *= k;
                    cur += base;
                }
                if(cur == x) return to_string(k);
            }
        }
        return to_string(x - 1);
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day54】1239-串联字符串的最大长度"><a href="#【Day54】1239-串联字符串的最大长度" class="headerlink" title="【Day54】1239. 串联字符串的最大长度"></a>【Day54】1239. 串联字符串的最大长度</h2><h4 id="1239-串联字符串的最大长度"><a href="#1239-串联字符串的最大长度" class="headerlink" title="1239. 串联字符串的最大长度"></a><a href="https://leetcode-cn.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/" target="_blank" rel="noopener">1239. 串联字符串的最大长度</a></h4><p>给定一个字符串数组 arr，字符串 s 是将 arr 某一子序列字符串连接所得的字符串，如果 s 中的每一个字符都只出现过一次，那么它就是一个可行解。</p>
<p>请返回所有可行解 s 中最长长度。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：arr = [&quot;un&quot;,&quot;iq&quot;,&quot;ue&quot;]
输出：4
解释：所有可能的串联组合是 &quot;&quot;,&quot;un&quot;,&quot;iq&quot;,&quot;ue&quot;,&quot;uniq&quot; 和 &quot;ique&quot;，最大长度为 4。</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：arr = [&quot;cha&quot;,&quot;r&quot;,&quot;act&quot;,&quot;ers&quot;]
输出：6
解释：可能的解答有 &quot;chaers&quot; 和 &quot;acters&quot;。</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：arr = [&quot;abcdefghijklmnopqrstuvwxyz&quot;]
输出：26</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= arr.length &lt;= 16</li>
<li>1 &lt;= arr[i].length &lt;= 26</li>
<li>arr[i] 中只含有小写英文字母</li>
</ul>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    int maxLength(vector<string> &arr) {
        int ans = 0;
        vector<int> masks = {0};
        for (string &s : arr) {
            int mask = 0;
            for (char ch : s) {
                ch -= 'a';
                if ((mask >> ch) & 1) { // 若 mask 已有 ch，则说明 s 含有重复字母，无法构成可行解
                    mask = 0;
                    break;
                }
                mask |= 1 << ch; // 将 ch 加入 mask 中
            }
            if (mask == 0) {
                continue;
            }
            int n = masks.size();
            for (int i = 0; i < n; ++i) {
                int m = masks[i];
                if ((m & mask) == 0) { // m 和 mask 无公共元素
                    masks.push_back(m | mask);
                    ans = max(ans, __builtin_popcount(m | mask));
                }
            }
        }
        return ans;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day55】1600-皇位继承顺序"><a href="#【Day55】1600-皇位继承顺序" class="headerlink" title="【Day55】1600.皇位继承顺序"></a>【Day55】1600.皇位继承顺序</h2><h4 id="1600-皇位继承顺序"><a href="#1600-皇位继承顺序" class="headerlink" title="1600. 皇位继承顺序"></a><a href="https://leetcode-cn.com/problems/throne-inheritance/" target="_blank" rel="noopener">1600. 皇位继承顺序</a></h4><p>一个王国里住着国王、他的孩子们、他的孙子们等等。每一个时间点，这个家庭里有人出生也有人死亡。</p>
<p>这个王国有一个明确规定的皇位继承顺序，第一继承人总是国王自己。我们定义递归函数 Successor(x, curOrder) ，给定一个人 x 和当前的继承顺序，该函数返回 x 的下一继承人。</p>
<blockquote>
<p>Successor(x, curOrder):<br> 如果 x 没有孩子或者所有 x 的孩子都在 curOrder 中：<br>     如果 x 是国王，那么返回 null<br>     否则，返回 Successor(x 的父亲, curOrder)<br> 否则，返回 x 不在 curOrder 中最年长的孩子</p>
</blockquote>
<p>比方说，假设王国由国王，他的孩子 Alice 和 Bob （Alice 比 Bob 年长）和 Alice 的孩子 Jack 组成。</p>
<ol>
<li>一开始， curOrder 为 [“king”].</li>
<li>调用 Successor(king, curOrder) ，返回 Alice ，所以我们将 Alice 放入 curOrder 中，得到 [“king”, “Alice”] 。</li>
<li>调用 Successor(Alice, curOrder) ，返回 Jack ，所以我们将 Jack 放入 curOrder 中，得到 [“king”, “Alice”, “Jack”] 。</li>
<li>调用 Successor(Jack, curOrder) ，返回 Bob ，所以我们将 Bob 放入 curOrder 中，得到 [“king”, “Alice”, “Jack”, “Bob”] 。</li>
<li>调用 Successor(Bob, curOrder) ，返回 null 。最终得到继承顺序为 [“king”, “Alice”, “Jack”, “Bob”] 。</li>
</ol>
<p>通过以上的函数，我们总是能得到一个唯一的继承顺序。</p>
<p>请你实现 ThroneInheritance 类：</p>
<ul>
<li>ThroneInheritance(string kingName) 初始化一个 ThroneInheritance 类的对象。国王的名字作为构造函数的参数传入。</li>
<li>void birth(string parentName, string childName) 表示 parentName 新拥有了一个名为 childName 的孩子。</li>
<li>void death(string name) 表示名为 name 的人死亡。一个人的死亡不会影响 Successor 函数，也不会影响当前的继承顺序。你可以只将这个人标记为死亡状态。</li>
<li>string[] getInheritanceOrder() 返回 除去 死亡人员的当前继承顺序列表。</li>
</ul>
<p><strong>示例：</strong></p>
<p><strong>输入：</strong></p>
<pre><code>[&quot;ThroneInheritance&quot;, &quot;birth&quot;, &quot;birth&quot;, &quot;birth&quot;, &quot;birth&quot;, &quot;birth&quot;, &quot;birth&quot;, &quot;getInheritanceOrder&quot;, &quot;death&quot;, &quot;getInheritanceOrder&quot;]
[[&quot;king&quot;], [&quot;king&quot;, &quot;andy&quot;], [&quot;king&quot;, &quot;bob&quot;], [&quot;king&quot;, &quot;catherine&quot;], [&quot;andy&quot;, &quot;matthew&quot;], [&quot;bob&quot;, &quot;alex&quot;], [&quot;bob&quot;, &quot;asha&quot;], [null], [&quot;bob&quot;], [null]]</code></pre><p><strong>输出：</strong></p>
<pre><code>[null, null, null, null, null, null, null, [&quot;king&quot;, &quot;andy&quot;, &quot;matthew&quot;, &quot;bob&quot;, &quot;alex&quot;, &quot;asha&quot;, &quot;catherine&quot;], null, [&quot;king&quot;, &quot;andy&quot;, &quot;matthew&quot;, &quot;alex&quot;, &quot;asha&quot;, &quot;catherine&quot;]]</code></pre><p><strong>解释：</strong></p>
<pre><code>ThroneInheritance t= new ThroneInheritance(&quot;king&quot;); // 继承顺序：king
t.birth(&quot;king&quot;, &quot;andy&quot;); // 继承顺序：king &gt; andy
t.birth(&quot;king&quot;, &quot;bob&quot;); // 继承顺序：king &gt; andy &gt; bob
t.birth(&quot;king&quot;, &quot;catherine&quot;); // 继承顺序：king &gt; andy &gt; bob &gt; catherine
t.birth(&quot;andy&quot;, &quot;matthew&quot;); // 继承顺序：king &gt; andy &gt; matthew &gt; bob &gt; catherine
t.birth(&quot;bob&quot;, &quot;alex&quot;); // 继承顺序：king &gt; andy &gt; matthew &gt; bob &gt; alex &gt; catherine
t.birth(&quot;bob&quot;, &quot;asha&quot;); // 继承顺序：king &gt; andy &gt; matthew &gt; bob &gt; alex &gt; asha &gt; catherine
t.getInheritanceOrder(); // 返回 [&quot;king&quot;, &quot;andy&quot;, &quot;matthew&quot;, &quot;bob&quot;, &quot;alex&quot;, &quot;asha&quot;, &quot;catherine&quot;]
t.death(&quot;bob&quot;); // 继承顺序：king &gt; andy &gt; matthew &gt; bob（已经去世）&gt; alex &gt; asha &gt; catherine
t.getInheritanceOrder(); // 返回 [&quot;king&quot;, &quot;andy&quot;, &quot;matthew&quot;, &quot;alex&quot;, &quot;asha&quot;, &quot;catherine&quot;]</code></pre><p><strong>提示：</strong></p>
<ol>
<li>1 &lt;= kingName.length, parentName.length, childName.length, name.length &lt;= 15</li>
<li>kingName，parentName， childName 和 name 仅包含小写英文字母。</li>
<li>所有的参数 childName 和 kingName 互不相同。</li>
<li>所有 death 函数中的死亡名字 name 要么是国王，要么是已经出生了的人员名字。</li>
<li>每次调用 birth(parentName, childName) 时，测试用例都保证 parentName 对应的人员是活着的。</li>
<li>最多调用 105 次birth 和 death 。</li>
<li>最多调用 10 次 getInheritanceOrder 。</li>
</ol>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">class ThroneInheritance {
public:
    string root;
    unordered_map<string, bool> isdeath;
    unordered_map<string, vector<string>> family;
    ThroneInheritance(string kingName) {
        root = kingName;
    }

    void birth(string parentName, string childName) {
        family[parentName].push_back(childName);
    }

    void death(string name) {
        isdeath[name] = true;
    }

    void dfs(vector<string>& ans, string root) {
        if (!isdeath[root])
            ans.push_back(root);
        for (string str: family[root])
            dfs(ans, str);
    }

    vector<string> getInheritanceOrder() {
        vector<string> ans;
        dfs(ans, root);
        return ans;
    }
};

/**
 * Your ThroneInheritance object will be instantiated and called as such:
 * ThroneInheritance* obj = new ThroneInheritance(kingName);
 * obj->birth(parentName,childName);
 * obj->death(name);
 * vector<string> param_3 = obj->getInheritanceOrder();
 */<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day56】401-二进制手表"><a href="#【Day56】401-二进制手表" class="headerlink" title="【Day56】401.二进制手表"></a>【Day56】401.二进制手表</h2><h4 id="401-二进制手表"><a href="#401-二进制手表" class="headerlink" title="401. 二进制手表"></a><a href="https://leetcode-cn.com/problems/binary-watch/" target="_blank" rel="noopener">401. 二进制手表</a></h4><p>二进制手表顶部有 4 个 LED 代表 小时（0-11），底部的 6 个 LED 代表 分钟（0-59）。每个 LED 代表一个 0 或 1，最低位在右侧。</p>
<ul>
<li>例如，下面的二进制手表读取 “3:25” 。</li>
</ul>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2021/03/29/binary_clock_samui_moon.jpg" alt="（图源：WikiMedia - Binary clock samui moon.jpg ，许可协议：Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) ）"></p>
<p>给你一个整数 turnedOn ，表示当前亮着的 LED 的数量，返回二进制手表可以表示的所有可能时间。你可以 <strong>按任意顺序</strong> 返回答案。</p>
<p>小时不会以零开头：</p>
<ul>
<li>例如，”01:00” 是无效的时间，正确的写法应该是 “1:00” 。</li>
</ul>
<p>分钟必须由两位数组成，可能会以零开头：</p>
<p>例如，”10:2” 是无效的时间，正确的写法应该是 “10:02” 。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：turnedOn = 1
输出：[&quot;0:01&quot;,&quot;0:02&quot;,&quot;0:04&quot;,&quot;0:08&quot;,&quot;0:16&quot;,&quot;0:32&quot;,&quot;1:00&quot;,&quot;2:00&quot;,&quot;4:00&quot;,&quot;8:00&quot;]</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：turnedOn = 9
输出：[]</code></pre><p><strong>提示：</strong></p>
<ul>
<li>0 &lt;= turnedOn &lt;= 10</li>
</ul>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    vector<string> readBinaryWatch(int num) {
        vector<string> res;
        //直接遍历  0:00 -> 12:00   每个时间有多少1
        for (int i = 0; i < 12; i++) {
            for (int j = 0; j < 60; j++) {
                if (count1(i) + count1(j) == num) {
                    res.push_back(to_string(i)+":"+
                                  (j < 10 ? "0"+to_string(j) : to_string(j)));
                }
            }
        }
        return res;
    }
    //计算二进制中1的个数
    int count1(int n) {
        int res = 0;
        while (n != 0) {
            n = n & (n - 1);
            res++;
        }
        return res;
    }
};

<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day57】剑指-Offer-15-二进制中1的个数"><a href="#【Day57】剑指-Offer-15-二进制中1的个数" class="headerlink" title="【Day57】剑指 Offer 15.二进制中1的个数"></a>【Day57】剑指 Offer 15.二进制中1的个数</h2><h4 id="剑指-Offer-15-二进制中1的个数"><a href="#剑指-Offer-15-二进制中1的个数" class="headerlink" title="剑指 Offer 15. 二进制中1的个数"></a><a href="https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/" target="_blank" rel="noopener">剑指 Offer 15. 二进制中1的个数</a></h4><p>请实现一个函数，输入一个整数（以二进制串形式），输出该数二进制表示中 1 的个数。例如，把 9 表示成二进制是 1001，有 2 位是 1。因此，如果输入 9，则该函数输出 2。</p>
<p><strong>示例 1：</strong></p>
<pre><code>输入：00000000000000000000000000001011
输出：3
解释：输入的二进制串 00000000000000000000000000001011 中，共有三位为 &#39;1&#39;。</code></pre><p><strong>示例 2：</strong></p>
<pre><code>输入：00000000000000000000000010000000
输出：1
解释：输入的二进制串 00000000000000000000000010000000 中，共有一位为 &#39;1&#39;。</code></pre><p><strong>示例 3：</strong></p>
<pre><code>输入：11111111111111111111111111111101
输出：31
解释：输入的二进制串 11111111111111111111111111111101 中，共有 31 位为 &#39;1&#39;。</code></pre><p><strong>提示：</strong></p>
<ul>
<li>输入必须是长度为 32 的 二进制串 。</li>
</ul>
<blockquote>
<p>注意：本题与主站 191 题相同：<a href="https://leetcode-cn.com/problems/number-of-1-bits/" target="_blank" rel="noopener">https://leetcode-cn.com/problems/number-of-1-bits/</a></p>
</blockquote>
<p><strong>题解：</strong></p>
<p>右移再 &amp; 1</p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    int hammingWeight(uint32_t n) {
        int ans = 0;
        for (int i = 0; i < 32; i++) {
            ans += ((n >> i) & 1);
        }
        return ans;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day58】149-直线上最多的点数"><a href="#【Day58】149-直线上最多的点数" class="headerlink" title="【Day58】149. 直线上最多的点数"></a>【Day58】149. 直线上最多的点数</h2><h4 id="149-直线上最多的点数"><a href="#149-直线上最多的点数" class="headerlink" title="149. 直线上最多的点数"></a><a href="https://leetcode-cn.com/problems/max-points-on-a-line/" target="_blank" rel="noopener">149. 直线上最多的点数</a></h4><p>给你一个数组 points ，其中 points[i] = [xi, yi] 表示 <strong>X-Y</strong> 平面上的一个点。求最多有多少个点在同一条直线上。</p>
<p><strong>示例 1：</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/02/25/plane1.jpg" alt></p>
<pre><code>输入：points = [[1,1],[2,2],[3,3]]
输出：3</code></pre><p><strong>示例 2：</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/02/25/plane2.jpg" alt></p>
<pre><code>输入：points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
输出：4</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= points.length &lt;= 300</li>
<li>points[i].length == 2</li>
<li>-104 &lt;= xi, yi &lt;= 104</li>
<li>points 中的所有点 互不相同</li>
</ul>
<p><strong>题解：</strong></p>
<p>直接枚举，比较斜率</p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    int maxPoints(vector<vector<int>>& points) {
        int len = points.size();
        // 点的数量不够
        if(len < 3) {
            return len;
        }
        int maxNum = 2;
        // 遍历每两个点
        for(int i = 0; i < len - 1; i ++) {
            for(int j = i + 1; j < len; j ++) {
                // 统计斜率相等个数
                int count = 2;
                long long dx = points[i][0] - points[j][0];
                long long dy = points[i][1] - points[j][1];
                // 与其他点比较
                for(int k = j + 1; k < len; k ++) {
                    // 如果斜率相等
                    if(dx * (points[i][1] - points[k][1]) == dy * (points[i][0] - points[k][0])) {
                        count ++;
                    }
                }
                maxNum = max(maxNum, count);
                if(maxNum > len / 2) return maxNum;
            }  
        }
        return maxNum;
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="【Day59】752-打开转盘锁"><a href="#【Day59】752-打开转盘锁" class="headerlink" title="【Day59】752.打开转盘锁"></a>【Day59】752.打开转盘锁</h2><h4 id="752-打开转盘锁"><a href="#752-打开转盘锁" class="headerlink" title="752. 打开转盘锁"></a><a href="https://leetcode-cn.com/problems/open-the-lock/" target="_blank" rel="noopener">752. 打开转盘锁</a></h4><p>你有一个带有四个圆形拨轮的转盘锁。每个拨轮都有10个数字： ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’ 。每个拨轮可以自由旋转：例如把 ‘9’ 变为 ‘0’，’0’ 变为 ‘9’ 。每次旋转都只能旋转一个拨轮的一位数字。</p>
<p>锁的初始数字为 ‘0000’ ，一个代表四个拨轮的数字的字符串。</p>
<p>列表 deadends 包含了一组死亡数字，一旦拨轮的数字和列表里的任何一个元素相同，这个锁将会被永久锁定，无法再被旋转。</p>
<p>字符串 target 代表可以解锁的数字，你需要给出解锁需要的最小旋转次数，如果无论如何不能解锁，返回 -1 。</p>
<p><strong>示例 1:</strong></p>
<pre><code>输入：deadends = [&quot;0201&quot;,&quot;0101&quot;,&quot;0102&quot;,&quot;1212&quot;,&quot;2002&quot;], target = &quot;0202&quot;
输出：6
解释：
可能的移动序列为 &quot;0000&quot; -&gt; &quot;1000&quot; -&gt; &quot;1100&quot; -&gt; &quot;1200&quot; -&gt; &quot;1201&quot; -&gt; &quot;1202&quot; -&gt; &quot;0202&quot;。
注意 &quot;0000&quot; -&gt; &quot;0001&quot; -&gt; &quot;0002&quot; -&gt; &quot;0102&quot; -&gt; &quot;0202&quot; 这样的序列是不能解锁的，
因为当拨动到 &quot;0102&quot; 时这个锁就会被锁定。</code></pre><p><strong>示例 2:</strong></p>
<pre><code>输入: deadends = [&quot;8888&quot;], target = &quot;0009&quot;
输出：1
解释：
把最后一位反向旋转一次即可 &quot;0000&quot; -&gt; &quot;0009&quot;。</code></pre><p><strong>示例 3:</strong></p>
<pre><code>输入: deadends = [&quot;8887&quot;,&quot;8889&quot;,&quot;8878&quot;,&quot;8898&quot;,&quot;8788&quot;,&quot;8988&quot;,&quot;7888&quot;,&quot;9888&quot;], target = &quot;8888&quot;
输出：-1
解释：
无法旋转到目标数字且不被锁定。</code></pre><p><strong>示例 4:</strong></p>
<pre><code>输入: deadends = [&quot;0000&quot;], target = &quot;8888&quot;
输出：-1</code></pre><p><strong>提示：</strong></p>
<ul>
<li>1 &lt;= deadends.length &lt;= 500</li>
<li>deadends[i].length == 4</li>
<li>target.length == 4</li>
<li>target 不在 deadends 之中</li>
<li>target 和 deadends[i] 仅由若干位数字组成</li>
</ul>
<p><strong>题解：</strong></p>
<pre class="line-numbers language-c++"><code class="language-c++">class Solution {
public:
    int seen[10010];//记录搜到过的轮盘锁数字
    int ans = -1;
    bool dead[10010];//记录死亡数字
    int q[10010];//模拟队列
    int openLock(vector<string>& deadends, string target) { 
        for(auto d : deadends){

            //将死亡数字转int作为下标存储在dead数组中
            int tmp = stoi(d);
            dead[tmp] = 1;
        }

        //如果"0000"是死亡数字直接返回0,如果target为0000直接返回-1
        if(dead[0])return -1;
        if(target == "0000") return 0;
        int tar=stoi(target);
        bfs(tar);
        return ans;
    }

    int numsadd(int num)
    {
        if(num == 10)
        return -9;
        if(num == -1)
        return -9;
        else return 1;
    }

    void bfs(int target)
    {    
        //hh队头，tt队尾
        int hh=0,tt=0;

        //先将队头初始化为0,代表从"0000"开始旋转
        q[0] = 0;
        while(hh <= tt){
            auto t = q[hh++];
            int prev = t;

            for(int i = 1 ; i <= 1000 ; i *= 10){
                int num = t / i % 10; 
                int temp=t;

                //正向旋转当前位的数字
                int tmp = temp + numsadd(num+1)*i;
                if(!seen[tmp] && !dead[tmp]){

                    //满足条件就将temp插入队尾
                    q[++tt] = tmp;
                    //更新新转盘锁数字的操作次数
                    seen[tmp] = seen[prev]+1;
                }

                //反向旋转当前位的数字
                tmp = temp - numsadd(num-1)*i;
                if(!seen[tmp] && !dead[tmp]){
                    q[++tt] = tmp;
                    seen[tmp] = seen[prev]+1;
                }           
            }

            if(seen[target] != 0){
                ans = seen[target];
                break;
            }
        }
    }
};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>整整两个月就刷完啦，发现这些题更适合于找工作，而我目前没有这方面的需要，所以以后偶尔刷一下，有时间就发在博客上hh</p>

            </div>
            <hr />

            
            <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.88rem;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-large waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fa fa-close"></i></a>
            <h4 class="reward-title">写作不易，客官能否打赏一杯奶茶？</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="https://cdn.jsdelivr.net/gh/MUYIio/CDN@1.2/Images/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="https://cdn.jsdelivr.net/gh/MUYIio/CDN@1.2/Images/reward/wechat.jpg" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>
            

            <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    <div class="social-share" data-disabled="qzone" data-wechat-qrcode-helper="<p>微信里点“发现”->“扫一扫”二维码便可查看分享。</p>"></div>
    
</div>

<script src="/libs/share/js/social-share.min.js"></script>

            

    <div class="reprint" id="reprint-statement">
        <p class="reprint-tip">
            <i class="fa fa-exclamation-triangle"></i>&nbsp;&nbsp;
            <span>转载规则</span>
        </p>
        
            <div class="center-align">
                <a rel="license" href="https://creativecommons.org/licenses/by/4.0/deed.zh">
                    <img alt=""
                         style="border-width:0"
                         src="https://i.creativecommons.org/l/by/4.0/88x31.png"/>
                </a>
            </div>
            <br/>
            <span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/Text"
                  property="dct:title" rel="dct:type">
                    《暑假LeetCode刷题集合（下）》
                </span> 由
            <a xmlns:cc="http://creativecommons.org/ns#" href="/shu-jia-leetcode-shua-ti-ji-he-xia.html" property="cc:attributionName"
               rel="cc:attributionURL">
                Tyzhao
            </a> 采用
            <a rel="license" href="https://creativecommons.org/licenses/by/4.0/deed.zh">
                知识共享署名 4.0 国际许可协议
            </a>进行许可。
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>


        </div>
    </div>

    
    <link rel="stylesheet" href="/libs/gitalk/gitalk.css">
<link rel="stylesheet" href="/css/my-gitalk.css">

<div class="card gitalk-card" data-aos="fade-up">
    <div id="gitalk-container" class="card-content"></div>
</div>

<script src="/libs/gitalk/gitalk.min.js"></script>
<script>
    let gitalk = new Gitalk({
        clientID: '46697bb9a799731534b2',
        clientSecret: 'b4f73ab06fb0a67da32d620ebc395111f2d508ee',
        repo: 'muyiio.github.io',
        owner: 'MUYIio',
        admin: "MUYIio",
        id: 'shu-jia-leetcode-shua-ti-ji-he-xia.html',
        distractionFreeMode: false  // Facebook-like distraction free mode
    });

    gitalk.render('gitalk-container');
</script>
    

    

    

    

    
    <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments input[type=text],
    #vcomments input[type=email],
    #vcomments input[type=url],
    #vcomments textarea {
        box-sizing: border-box;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #42b983;
        font-weight: 500;
        text-decoration: underline;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div id="vcomments" class="card-content"></div>
</div>

<script src="/libs/valine/av-min.js"></script>
<script src="/libs/valine/Valine.min.js"></script>
<!-- <script src="//unpkg.com/valine@latest/dist/Valine.min.js"></script> -->

<script>
    new Valine({
        el: '#vcomments',
        appId: '2XytdtE76cEw5tyzKupUSM2s-gzGzoHsz',
        appKey: 'CFpPusBW6xLPhs8OQUaCkX2c',
        notify: 'true' === 'true',
        verify: 'false' === 'true',
        visitor: 'false' === 'true',
        avatar: 'wavatar',
        pageSize: '10',
        lang: 'zh-cn',
        placeholder: '如果你没有GitHub账号，还可以在这里评论啦！'
    });
</script>

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fa fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/c-zhong-guan-yu-lambda-biao-da-shi-de-zong-jie.html">
                    <div class="card-image">
                        
                        
                        <img src="https://cdn.jsdelivr.net/gh/MUYIio/CDN@1.2/Images/featureimages/37.jpg" class="responsive-img" alt="C++ 中关于Lambda 表达式的总结">
                        
                        <span class="card-title">C++ 中关于Lambda 表达式的总结</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            Lambda表达式是C++ 11新特性之一，总的来说就是一个函数。
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="fa fa-clock-o fa-fw icon-date"></i>2021-10-18
                        </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/C/" class="post-category" target="_blank">
                                    C++
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Lambda/" target="_blank">
                        <span class="chip bg-color">Lambda</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fa fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/shi-yong-java-kai-fa-yi-ge-ji-shi-ben.html">
                    <div class="card-image">
                        
                        
                        <img src="https://cdn.jsdelivr.net/gh/MUYIio/CDN@1.2/Images/featureimages/7.jpg" class="responsive-img" alt="使用Java开发一个记事本">
                        
                        <span class="card-title">使用Java开发一个记事本</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            大二下的Java课程设计，仿的Windows记事本，使用Java Swing组件开发。
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="fa fa-clock-o fa-fw icon-date"></i>2021-07-17
                            </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/Java/" class="post-category" target="_blank">
                                    Java
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Demo/" target="_blank">
                        <span class="chip bg-color">Demo</span>
                    </a>
                    
                    <a href="/tags/Notepad/" target="_blank">
                        <span class="chip bg-color">Notepad</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>
</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('120')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: Shawlon`s Blog<br />'
            + '作者: Tyzhao<br />'
            + '链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () { bodyElement.removeChild(newdiv); }, 200);
    });
</script>

    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="fa fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fa fa-list"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            // headingsOffset: -205,
            headingSelector: 'h1, h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h1, h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).slideUp(500);
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).slideDown(500);
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>
    

</main>


<script src="https://cdn.bootcss.com/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
    MathJax.Hub.Config({
        tex2jax: {inlineMath: [['$', '$'], ['\(', '\)']]}
    });
</script>

<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>
<!-- 代码语言 -->
<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>
<!-- 代码块复制 -->
<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>
<script type="text/javascript" src="/libs/codeBlock/clipboard.min.js"></script>
<!-- 代码块收缩 -->
<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script> 
<!-- 代码块折行 -->
<style type="text/css">code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }</style>


    <footer class="page-footer bg-color">
    <div class="container row center-align">
       <div class="Copy-right">
            &copy; 2021 Yshawlon. All Rights Reserved.

           <img src="https://cdn.jsdelivr.net/gh/MUYIio/CDN@1.2/Images/avatars/icp.png" style="width:18px;height:18px;margin-bottom:-2px" alt="ICP">
           <a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">渝ICP备2020014220号-1</a>丨
           <img src="https://cdn.jsdelivr.net/gh/MUYIio/CDN@1.2/Images/avatars/moeicp.png" style="width:18px;height:18px;margin-bottom:-3px" alt="MOE ICP">
           <a href="https://icp.gov.moe/" target="_blank">萌ICP备20216999号</a>丨            
           <!--<a href="/sitemap.xml" target="_blank">站点地图</a>丨-->
           
            &nbsp;<i class="fa fa-area-chart"></i>&nbsp;站点总字数:&nbsp;
            <span class="white-color">72.3k
             丨            
            <a href="https://tongji.baidu.com/web/welcome/ico?s=df42dpc7224a5f6a8d435" target="_blank">百度统计</a>丨
           <script type="text/javascript">document.write(unescape("%3Cspan id='cnzz_stat_icon_1278720284'%3E%3C/span%3E%3Cscript src='https://s9.cnzz.com/z_stat.php%3Fid%3D1278720284%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"));</script>

            <span id="sitetime"></span>

            
            
            
            
            <span id="busuanzi_container_site_pv" style='display:none'>
                <i class="fa fa-users"></i>
                本站总访问量 <span id="busuanzi_value_site_pv" class="red-color"></span>
            </span>
            
            
            <span id="busuanzi_container_site_uv" style='display:none'>
               人次,&nbsp;<i class="fa fa-user"></i>访客数 <span id="busuanzi_value_site_uv" class="blue-color"></span> 人.
            </span>
            
            
        </div>        
        <div class="social-link social-statis">
    <a href="https://github.com/MUYIio" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fa fa-github"></i>
    </a>



    <a href="https://www.csdn.net/weixin_45682081" class="tooltipped" target="_blank" data-tooltip="访问我的CSDN主页" data-position="top" data-delay="50">
        <i class="fa fa-codiepie"></i>
    </a>



    <a href="https://www.zhihu.com/zhihu.com/people/muyiio" class="tooltipped" target="_blank" data-tooltip="访问我的知乎" data-position="top" data-delay="50">
        <i class="fa fa-inverse">知</i>
    </a>



    <a href="https://user.qzone.qq.com/1571504536" class="tooltipped" target="_blank" data-tooltip="访问我的QQ空间" data-position="top" data-delay="50">
        <i class="fa fa-qq"></i>
    </a>



    <a href="mailto:1571504536@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fa fa-envelope-open"></i>
    </a>



    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fa fa-rss"></i>
    </a>
</div>


    </div>
    <div class="container row center-align">
    <div class="github-badge">
      <a style="color: #fff" rel="license" href="https://hexo.io/" target="_blank" title="由 Hexo 强力驱动">
      <span class="badge-subject">Powered</span><span class="badge-value bg-blue">Hexo</span></a>
    </div>
    <div class="github-badge">
      <a style="color: #fff" rel="license" href="https://github.com/" target="_blank" title="静态网页托管于 GitHub Pages 和 Coding Pages">
      <span class="badge-subject">Hosted</span><span class="badge-value bg-brightgreen">GitHub & Coding</span></a>
    </div>
    <div class="github-badge">
      <a style="color: #fff" rel="license" href="https://www.cloud.tencent.com/" target="_blank" title="腾讯云提供域名相关服务">
      <span class="badge-subject">DNS</span><span class="badge-value bg-blueviolet">Tencent cloud</span></a>
    </div>
    <div class="github-badge">
      <a style="color: #fff" rel="license" href="https://www.jsdelivr.com/" target="_blank" title="jsDelivr 提供 CDN 加速服务">
      <span class="badge-subject">CDN</span><span class="badge-value bg-orange">jsDelivr</span></a>
    </div>
    <div class="github-badge">
        <a style="color: #fff" rel="license" href="https://github.com/blinkfox/hexo-theme-matery/" target="_blank" title="站点使用 Matery 主题">
      <span class="badge-subject">Theme</span><span class="badge-value bg-blue">Matery</span></a>
    </div>
    <div class="github-badge">
      <a style="color: #fff" rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" title="本站点采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可">
      <span class="badge-subject"><i class="fa fa-copyright"></i></span><span class="badge-value bg-lightgrey">BY-NC-SA 4.0</span></a>
    </div>
    <div class="github-badge">
      <a style="color: #fff" rel="license" href="https://996.icu/" target="_blank" title="支持 996.ICU">
      <span class="badge-subject">Link</span><span class="badge-value bg-red">996.ICU</span></a>
    </div>
    <div class="github-badge">
      <span class="badge-subject">WordCount</span><span class="badge-value bg-blueviolet">72.3k</span>
    </div>
</footer>

<div class="progress-bar"></div>

<!-- 不蒜子计数初始值纠正 -->
<script>
    $(document).ready(function () {

        var int = setInterval(fixCount, 50);
        var pvcountOffset = 80000;
        var uvcountOffset = 20000;

        function fixCount() {
            if (document.getElementById("busuanzi_container_site_pv").style.display != "none") {
                $("#busuanzi_value_site_pv").html(parseInt($("#busuanzi_value_site_pv").html()) + pvcountOffset);
                clearInterval(int);
            }
            if ($("#busuanzi_container_site_pv").css("display") != "none") {
                $("#busuanzi_value_site_uv").html(parseInt($("#busuanzi_value_site_uv").html()) + uvcountOffset); // 加上初始数据 
                clearInterval(int);
            }
        }
    });
</script>

<script language=javascript>
    function siteTime() {
        window.setTimeout("siteTime()", 1000);
        var seconds = 1000;
        var minutes = seconds * 60;
        var hours = minutes * 60;
        var days = hours * 24;
        var years = days * 365;
        var today = new Date();
        var todayYear = today.getFullYear();
        var todayMonth = today.getMonth() + 1;
        var todayDate = today.getDate();
        var todayHour = today.getHours();
        var todayMinute = today.getMinutes();
        var todaySecond = today.getSeconds();
        /* Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
        year - 作为date对象的年份，为4位年份值
        month - 0-11之间的整数，做为date对象的月份
        day - 1-31之间的整数，做为date对象的天数
        hours - 0(午夜24点)-23之间的整数，做为date对象的小时数
        minutes - 0-59之间的整数，做为date对象的分钟数
        seconds - 0-59之间的整数，做为date对象的秒数
        microseconds - 0-999之间的整数，做为date对象的毫秒数 */
        var t1 = Date.UTC(2020, 01, 01, 00, 00, 00); //北京时间2018-2-13 00:00:00
        var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
        var diff = t2 - t1;
        var diffYears = Math.floor(diff / years);
        var diffDays = Math.floor((diff / days) - diffYears * 365);
        var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
        var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) / minutes);
        var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours - diffMinutes * minutes) / seconds);
        document.getElementById("sitetime").innerHTML = " | 本站已运行 " + diffYears + " 年 " + diffDays + " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
    }/*因为建站时间还没有一年，就将之注释掉了。需要的可以取消*/
    siteTime();
</script>

    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fa fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fa fa-angle-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <script type="text/javascript"> var OriginTitile = document.title, st; document.addEventListener("visibilitychange", function () { document.hidden ? (document.title = "Σ(っ °Д °;)っ喔哟，崩溃啦！", clearTimeout(st)) : (document.title = "φ(゜▽゜*)♪咦，又好了！", st = setTimeout(function () { document.title = OriginTitile }, 3e3)) })
    </script>

    <!-- Global site tag (gtag.js) - Google Analytics -->

<script async src="https://www.googletagmanager.com/gtag/js?id="></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag() {
        dataLayer.push(arguments);
    }

    gtag('js', new Date());
    gtag('config', '');
</script>



    <!--鼠标点击特效-->
    


    <!--不蒜子计数-->
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    


    <!-- 雪花特效 -->
    
    
    <!--动态线条背景-->
    <script type="text/javascript"
    color="220,220,220" opacity='0.7' zIndex="-2" count="200" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js">
    </script>

    <!--鼠标跟随樱花特效 -->
    
        <script type="text/javascript" src="/js/fairyDustCursor.js"></script>
    



    <!--单击显示文字-->
    

    <!--鼠标点击粒子特效-->
    
    <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none;" ></canvas> 
    <script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script> 
    <script type="text/javascript" src="/js/fireworks.js"></script>
    

    <script async src =“ https://www.jsdelivr.com/terms/acceptable-use-policy-jsdelivr-net ”>
    </script>


    <!--自定义看板娘-->
    <!-- <script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>  -->
    <script src="/live2d-widget/autoload.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/>


</body>
</html>